Choose where you’d like to start

toDateTimeString

Note:The toDateTimeString built-in function is applicable to all Zoho services.

Overview

The toDateTimeString function is a built-in function used for managing date and time data efficiently. Primarily, this function is used to handle Unix time conversion, simplifying the process of working with timestamps in Unix-based systems.

  1. Date Format format: In addition to converting Unix time, this function can also adjust input date-time values to various accepted date-time formats, enhancing compatibility with diverse date representations.
  2. Timezone: Additionally, the toDateTimeString function enables seamless conversion of dates and times between different time zones. This capability guarantees consistent handling of time-related data, a critical necessity for globally used or distributed applications.

Note:

  • Daylight saving is taken into account by default wherever required. This means the returned date will be automatically adjusted for DST.
  • The output (for example, month, timezone, or day) is in English for all users, regardless of their locale.

Return Type

  • TEXT

Syntax

<result> = <input_data>.toDateTimeString(<dateTimeFormat>, <timeZone>);

(or)

<result> = toDateTimeString(<input_data>, <dateTimeFormat>, <timeZone>);

where,

ParameterData typeDescription
<result>TEXTResult that will contain the returned date value.
Note:The date-time format and timezone will be converted to the preference specified using <dateTimeFormat> and <timeZone> parameters.
<input_data>NUMBER

The data is returned in the specified date-time format or timezone as indicated in the input.

Note:

  • The input format for date-time and timezone is determined by the service settings. 
  • The numeric value 0 represents the date-time value of 01-Jan-1970 in the UTC timezone. Each increase of 1000 adds one second to the date value, while each decrease of 1000 subtracts one second. For instance, the number 1000 corresponds to a date value of 01-01-1970 00:00:01.
<dateTimeFormat>TEXT

The format in which the date time value will be returned.

Note:

  • Within this param, you can only specify date-time literals which represent the respective components of a date or time value.
  • If this param is not specified, the date-time value will be returned in a format specified in application settings.
<timeZone>TEXT

Time zone in which the date-time value will be returned.

Note:

Learn more about the supported date-time and time formats.

Applicable Date-Time Literals

LetterDate and Time Component
Era designator
y

Calendar year

Examples:

y - 2019

yy -19

yyy  - 2019

dateValue = '29-Dec-2019';
info dateValue.toDateString("yyyy"); // returns 2019

Y

Week year

Examples:

Y - 2019

YY -19

YYY  - 2019

dateValue = '29-Dec-2019';
info dateValue.toDateString("YYYY"); // returns 2020

M

Month in year

Examples:

M - 1

MM - 01

MMM - Jan

MMMM - January

wWeek in year
WWeek in month
DDay in year
dDay in month
FDay of week in month
E

Day name in week

Examples:

E - Tue

EEEE - Tuesday

uDay number of week
aam/pm marker
HHour in day (0-23)
kHour in day (1-24)
KHour in am/pm (0-11)
hHour in am/pm (1-12)
mMinute in hour
sSecond in minute
SMillisecond
zGeneral time zone
ZRFC time zone
XISO 8601 time zone

Examples

Here is an example of how the toDateTimeString can be used:

ctime = 1693905560373; // This is a date-time value represented in Unix time format.
 info toDateTimeString(ctime,"MMM dd, yy 'at' hh:mm:ss z, E","IST");
// Returns Sep 05, 23 at 02:49:20 IST, Tue

Related Topics

Get Started Now

Execute