reformatDate

String sutil.reformatDate ( String date, String dateFormatFrom, String dateFormatTo ) (professional and enterprise editions only)
String sutil.reformatDate ( String date, String dateFormatTo ) (enterprise edition only)

Description

Change a date format.

Parameters

  • date Date that is being reformatted, as a string.
  • dateFormatFrom (optional) The format of the date that is being reformated. The date format follows Sun's SimpleDateFormat.
  • dateFormatTo The format that the date is being changed to. If dateFormatFrom is being used this should also follow Sun's SimpleDateFormat. If dateFormatFrom is left off then the date format should follow PHP's date format. In the later method you can also use timestamp as the value of this parameter and it will return the timestamp corresponding to the date. Note also how PHP treats dashes and dots: "Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed."

Return Values

Returns formatted date according to the specified format, as a string.

Change Log

Version Description
5.0 Moved from session to sutil.
4.5 Available for professional and enterprise editions. Unspecified source format available for enterprise edition.

The date formats are not the same for the two methods. Read carefully.

Examples

Reformat Date from Specified Format

 // Reformats the date shown to the format "2010-01-01".
 // This uses Sun's Date Formats

 sutil.reformatDate( "01/01/2010", "dd/MM/yyyy", "yyyy-MM-dd" );

Reformat Date from Unspecified Format

 // Reformats the date shown to the format "2010-01-01".
 // This uses PHP's Date Formats

 sutil.reformatDate( "01/01/2010", "Y-m-d" );