NexJ Logo

DateTimeFormat()

Formats a date using the specified date, time zone, and pattern. This function takes a date value and two string values as arguments and returns the date as a formatted string value that can include both date and time.

Syntax

DateTimeFormat(<date>, <time_zone>, <pattern>)

Input

date

date

The date to format.

time_zone

string

(Optional) The time zone code. This argument specifies the time zone of the date. For example, if you want the date to be in Eastern Standard Time (EST), enter the time zone argument "EST". If you do not specify a time zone, the local time zone of the user who is completing the form is used.

pattern

string

(Optional) The pattern used to format the date. This argument specifies the format that you want the date to be displayed in. For example, if you want to display the date as two-digit numbers, enter the pattern argument "dd/mm/yy hh:mm". If you do not specify a pattern, the default pattern applied is "MMMM d, yyyy h:mma z".

Output

string

Examples

Assume that you have a form in which there is a date field question with the reference name date_of_birth. In the field, the user chooses January 31, 2000. The user is in the EST time zone.

  • The expression DateTimeFormat($date_of_birth) returns "January 31, 2000 12:00AM EST".
  • The expression DateTimeFormat($date_of_birth, "PST") returns "January 30, 2000 9:00PM PST", because in this example the time zone argument changes the specified date to Pacific Standard Time, which is January 30, 2000 9:00 PM PST.
  • The expression DateTimeFormat($date_of_birth, "EST", "dd/mm/yyyy hh:mm") returns "31/01/2000 12:00".

Time zones
Date and time patterns