toString

This topic describes the syntax and usage of the toString function in Zoho Creator .

Description

The toString function converts any type of expression to string. 

Syntax

expression.toString()

(or)

toString(expression)

//this format is supported only in the free-flow scripting mode of script builder.

The toString function syntax has the following arguments:

expression -  Required. The expression to be converted to a string.

Example

(12345).toString();             //returns "12345"

SaleDate.toString();     //returns string format of date field called "SaleDate"

toString(12345);             //returns "12345"

toString(SaleDate);              //returns string format of date field called "SaleDate"

Behavior of toString() when applied to datetime value:

  • toString(<date/datetime>) function on a date/datetime value will output date string in the format specified in the application setting.
  • If you want to override the time format, you can use <date/datetime>.toString("date format as string"). eg. toString("dd-MM-yyyy")
  • If you wish to convert the string to different timezone, you can use <date/datetime>.toString("date format as string","<Time Zone>"). eg. toString("dd-MM-yyyy","Asia/Calcutta")​

You can use the following params for various date/time values, for example '<date/time>'.tostring("<Param>
");

ParamDesription
GEra designator (before christ, after christ)
yYear (e.g. 12 or 2012). Number of y's determine length of format (e.g. yy, yyy or yyyyy)
MMonth in year. Number of M's determine length of format (e.g. MM, MMM or MMMMM)
dDay in month. Number of d's determine length of format (e.g. d or dd)
hHour of day, 1-12 (AM / PM). Number of h's determine length of format (e.g. h or hh or hhh)
HHour of day, 0-23. Number of H's determine length of format (e.g. H or HH or HHH)
mMinute in hour, 0-59. Number of m's determine length of format (e.g. m or mm or mmm)
sSecond in minute, 0-59. Number of s's determine length of format (e.g. s or ss or sss)
SMillisecond in second, 0-999. Number of S's determine length of format (e.g. S or SS or SSS)
EDay in week (e.g Monday, Tuesday etc.)
DDay in year (1-366)
FDay of week in month (e.g. 1st Thursday of December)
wWeek in year (1-53)
WWeek in month (0-5)
aAM / PM marker
kHour in day (1-24, unlike HH's 0-23)
KHour in day, AM / PM (0-11)
zTime Zone

To get the time portion from a date-time string use the toString() function, as shown in the below code:

a = ’01-Oct-2010 10:11:12′ ;
info a.toString(“HH:mm:ss”);

This returns the Time portion string from date-time value.