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.
- string changedateformat(string inputdate) //input date is string in format "DD-MMM-YYYY". for eg. 10-Sep-2010.
- {
- dt = input.inputdate.toDate("dd-MMM-yyyy"); // converting input string to date object specifying its format.
- dt1 = dt.toString("yyyy-MM-dd"); // Now we convert the date object to string with our required format.
- return dt1; // returning the string object.
- }