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: Apart from 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. i.e., 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>TEXT

result which 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 reverted in the date-time format or timezone that is mentioned in the input.

Note:

  • The input format for date-time and timezone is determined by the service settings.
  • The number 0 stands for the date-time value 01-Jan-1970 in UTC timezone, and every increase in 1000 will add 1 second to the date value, and every decrease in 1000 will subtract 1 second from the date value.
    So, the number 1000 will return 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:

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:

Note: This example is provided with the assumption that the user's timezone is set to 'Asia/Kolkata.'

The outputs may vary if tested with different time zones.

ctime=1693905560373; 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