How to convert Date format in Deluge Script

How to convert Date format in Deluge Script

To convert the date format from "DD-MMM-YYYY" to "YYYY-MM-DD", change the string with first format to date. Then convert that date object to a string specifying the second format. The below is the sample function which converts the format of the date to "YYYY-MM-DD" and return it as a string. Please refer to it. 


  1. string changedateformat(string inputdate) //input date is string in format "DD-MMM-YYYY". for eg. 10-Sep-2010.
  2. {
  3.     dt = input.inputdate.toDate("dd-MMM-yyyy"); // converting input string to date object specifying its format.
  4.     dt1 = dt.toString("yyyy-MM-dd");   // Now we convert the date object to string with our required format.
  5.     return dt1;   // returning the string object.
  6. }