Choose where you’d like to start

text

Overview

The text function takes a numerical expression and returns it in the desired format.

Note:

  • The function can format numbers, decimals and dates.

Return Type

  • TEXT

Syntax

<variable> = <expression>.toText(<formatText>);

where,

ParameterData typeDescription
<variable>TEXTVariable which will contain the returned value.
<expression>DATE-TIME / DECIMAL / NUMBERThe expression which needs to be formatted.

<formatText>

TEXT

The text expression with which the desired expression needs to be formatted.

Note:

  • When date-time values are to be formatted, the date-time literals provided can be used.
  • If this param is not specified, a runtime error is thrown.

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.toText("yyyy"); // returns 2019

Y

Week year

Examples:

Y - 2019

YY -19

YYY  - 2019

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

M

Month in year

Examples:

M - 1

MM - 01

MMM - 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

Below are the various ways in which date-time values, decimal and number values can be formatted.

 leadingZero  =  2434.text("000000000"); // 000002434
 separateValue  =  "123123456".text("##,###"); // 123,123,456
 dayOfYear  =  "02/04/2020".text("DDD"); // 035
 monthOfYear  =  "02/04/2020".text("MM"); // 02

 dayName  =  "02/04/2020".text("EEEE"); // Tuesday
 currencyFormat  =  "12345654.1234".text("$#,##0.00"); // $12,345,654.12
 dateFormat  =  zoho.currenttime.text("MM/dd/YY"); // 02/04/20
 dateFormat2  =  zoho.currentdate.text("MMM dd, yy 'at' hh:mm:ss, E"); // Feb 04, 20 at 12:00:00, Tue
 noParam  =  zoho.currenttime.text(); // Run-time error: No. of arguments mismatches for the function text

Related Links

Get Started Now

Execute