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.
- }
- NOTE :
The Date and Time pattern strings are mentioned below, - Date – dd
- Month – MM (or) MMM (or) MMMM
- Year – yy (or) yyyy
- 12 hour format – hh
- 24 hour format – HH
- minute – mm
- second – ss
- AM/PM marker – a