toTime
Table of Contents
Overview
The toTime function takes expression, dateTimeMapping, and timeZone as arguments. It returns the expression (representing a date-time value) in the date-time format and (converted to) timezone as specified in application settings.
Note:
- Time zone specified in application settings is considered as the default time zone.
- The dateTimeMapping param is used to specify which values in the expression stand for which date time components.
- The timeZone param is used to denote the time zone in which the given date-time value (in the expression) falls in.
Return Type
- DATE-TIME
Syntax
<variable> = <expression>.toTime(<dateTimeMapping>, <timeZone>);
where,
Parameter | Data type | Description |
<variable> | DATE-TIME | Variable which will contain the formatted date-time value. |
<expression> | TEXT/NUMBER/DATE-TIME | The expression (containing a valid date time format) which will be returned in date format. When the data type is NUMBER:
When the data type is Date-time, the additional parameters (mentioned below) are ignored. And, the function will throw a runtime error if the month value exceeds the number of months in a year, or the day value exceeds the number of days in a month. |
<dateTimeMapping> (optional) | DATE-TIME | The format in which the date-time value must be represented. Applies when the given expression is of Text data-type. You can specify date-time literals (as mentioned in the below table) to denote the date value components in the expression as required. The date-time literals must be separated using the exact same separator as given in the expression. When the month is specified as numerical value, the month pattern letter "M" must be specified as M or MM. When the month is specified as a text value, the month pattern letter "M" must be specified as MMM (or may contain more number of M's). |
<timeZone> (optional) | TEXT | Time Zone in which the given date-time value will be taken. Applies when the given expression is of Text data-type. Value must be specified exactly as given in the TZ database name column on this page. If the function fails to recognize the specified time zone, it will return the time value converted to GMT time zone. |
Applicable Date-Time literals:
Literal | Date and Time component |
---|---|
y | Year |
M | Month in year |
d | Day in month |
a | am/pm marker |
H | Hour in day (0-23) |
h | Hour in am/pm (1-12) |
m | Minute in hour |
s | Second in minute |
Examples
//Assuming, date time format set in application settings is dd-MMM-yyyy and Time Zone set in application settings is Indian Standard Time (which is 2 hours and 30 minutes ahead of Moscow) dateTimeString = "01,11,19 1:30:00 pm"; info toTime(dateTimeString, "MM,d,yyyy hh:mm:ss a", "Europe/Moscow"); //returns 11-Jan-0019 16:00:00