Date formulas

Video guide: Learn how to transform dates with formula mode

Workato supports a variety of date and datetime formulas.

Formulas in Workato are allowlisted Ruby methods. Syntax and functionality for these formulas are generally unchanged. Most formulas return an error and stop the job if the formula operates on nulls (expressed as nil in Ruby), except for present?, presence, and blank?.

You can refer to the Ruby documentation on time for more information. However, only allowlisted Ruby methods are supported. Contact your Customer Success Manager to request new formulas for the allowlist.

Date arithmetic

Use the following keywords to perform arithmetic with date and datetime data:

  • seconds
  • minutes
  • days
  • months
  • years

When combined with a formula, you can perform addition and subtraction.

Sample usage

Date ArithmeticOutput
"2020-01-01".to_date + 2.days"2020-01-03"
"2020-01-01".to_date - 2.days"2019-12-30"
"2020-01-01".to_date + 2.months"2020-03-01"
"2020-01-01".to_date - 2.months"2019-11-01"
"2020-01-01".to_date + 2.years"2022-01-01"
"2020-01-01".to_date - 2.years"2018-01-01"

now

Returns the time and date at runtime in US Pacific Time Zone (PST).

Sample usage

FormulaResult
now"2022-02-01T07:00:00.000000-08:00"
now + 8.hours"2022-02-01T15:00:00.000000-08:00"
now + 2.days"2022-02-03T07:00:00.000000-08:00"

How it works

The formula calculates the timestamp when the job is processed. Each step using this formula returns the timestamp at which the step runs.

Output datapill

If you only want the date without the time, try using the today formula instead.

See also

  • today: Returns the date at runtime.
  • in_time_zone: Converts a time value to a different time zone.

today

Returns the date at runtime in US Pacific Time Zone.

Sample usage

FormulaResult
today"2022-02-01"
today + 8.hours"2022-02-01T15:00:00.000000-08:00"
today + 2.days"2022-02-03"

How it works

The formula calculates the timestamp when the job is processed. Each step using this formula returns the date at which the step runs.

Output datapill

If you want the date and time, try using the now formula instead.

See also

  • now: Returns the time and date at runtime.
  • in_time_zone: Converts a time value to a different time zone.

from_now

Returns a future timestamp by a specified time duration. The timestamp is calculated at runtime.

Syntax

Unit.from_now

  • Unit - A time value to offset.

Sample usage

FormulaResult
30.seconds.from_now"2022-02-01T07:00:30.000000-08:00"
2.months.from_now"2022-04-01T07:00:00.000000-08:00"
3.days.from_now"2022-02-04T07:00:00.000000-08:00"

How it works

The formula calculates the current timestamp and offsets by a specified time duration. This timestamp is calculated when the job is processed. Each step using this formula returns a timestamp.

UNITS

You can use any of the following units: seconds, minutes, hours, days, months, or years.

See also

  • ago: Returns an earlier timestamp by a specified time duration.
  • now: Returns the time and date at runtime.
  • today: Returns the date at runtime.

ago

Returns an earlier timestamp by a specified time duration. The timestamp is calculated at runtime.

Syntax

Unit.ago

  • Unit - A time value to offset.

Sample usage

FormulaResult
2.months.ago"2020-10-04 14:45:29 -0700"
3.days.ago"2020-12-01 14:45:29 -0700"
30.seconds.ago"2020-12-04 14:15:29 -0700"

How it works

The formula calculates the current timestamp and offsets by a specified time duration. This timestamp is calculated when the job is processed. Each step using this formula returns a timestamp for each step that runs.

Units

You can use any of the following units: seconds, minutes, hours, days, months, or years.

See also

  • from_now: Returns a future timestamp by a specified time duration.
  • now: Returns the time and date at runtime.
  • today: Returns the date at runtime.

wday

Returns day of the week. Sunday returns 0, Monday returns 1.

Syntax

Date.wday

  • Date - A date or datetime datatype.

Sample usage

ExampleResult
today.wday4
"01/12/2020".to_date(format:"DD/MM/YYYY").wday2

How it works

The formula calculates the current day when the job is processed. The day of the week is converted into an integer output. Sunday = 0, Monday = 1.

Quicktip: Convert to date datatype

This formula only works with date or datetime datatype. Use to_date to convert a string into a date datatype.

See also

  • yday: Returns the day number of the year.
  • yweek: Returns the week number of the year.

yday

Returns day number of the year.

Syntax

Date.yday

  • Date - A date or datetime datatype.

Sample usage

ExampleResult
today.yday338
"2020-01-01".to_date(format:"YYYY-MM-DD").yday1
"2020-02-01".to_date(format:"YYYY-MM-DD").yday32

How it works

The formula calculates the current day when the job is processed. The day of the year is converted to an integer output.

Quicktip: Convert to date datatype

This formula only works with date or datetime datatype. Use to_date to convert a string into a date datatype.

See also

  • wday: Returns the day number of the week.
  • yweek: Returns the week number of the year.

yweek

Returns week number of the year.

Syntax

Date.yweek

  • Date - A date or datetime datatype.

Sample usage

ExampleResult
today.yweek49
"2020-01-01".to_date(format:"YYYY-MM-DD").yweek1
"2020-02-01".to_date(format:"YYYY-MM-DD").yweek5

How it works

The formula calculates the current day when the job is processed. The week of the year is converted to an integer output.

Quicktip: Convert to date datatype

This formula only works with date or datetime datatype. Use to_date to convert a string into a date datatype.

See also

  • wday: Returns the day number of the week.
  • yday: Returns the day number of the year.

beginning_of_hour

Returns datetime for top-of-the-hour for a given datetime.

Syntax

Datetime.beginning_of_hour

  • Datetime - An input datetime.

Sample usage

FormulaResult
today.to_time.beginning_of_hour"2020-12-02T16:00:00.000000-07:00"
"2020-06-01T01:30:45.000000+00:00".to_time.beginning_of_hour"2020-06-01T01:00:00.000000+00:00"
"2020-06-01".to_time.beginning_of_hour"2020-06-01T00:00:00.000000+00:00"

beginning_of_day

Returns datetime for midnight on date of a given date/datetime.

Syntax

Date.beginning_of_day

  • Date - An input date or datetime.

Sample usage

FormulaResult
today.beginning_of_day"2020-12-02T00:00:00.000000-07:00"
"2020-06-01".to_date.beginning_of_day"2020-06-01T00:00:00.000000+00:00"
"2020-06-01T01:30:45.000000+00:00".beginning_of_day"2020-06-01T00:00:00.000000+00:00"

beginning_of_week

Returns date for the start of the week (Monday) for a given date/timestamp.

Syntax

Date.beginning_of_week

  • Date - An input date or datetime.

Sample usage

FormulaResult
today.beginning_of_week"2020-11-30T00:00:00.000000+00:00"
"2020-06-01".to_date.beginning_of_week"2020-06-01T00:00:00.000000+00:00"
"2020-06-01T01:30:45.000000+00:00".beginning_of_week"2020-06-01T00:00:00.000000+00:00"

beginning_of_month

Returns first day of the month for a given date/datetime.

Syntax

Date.beginning_of_month

  • Date - An input date or datetime.

Sample usage

FormulaResult
today.beginning_of_month"2020-12-01T00:00:00.000000+00:00"
"2020-06-01".to_date.beginning_of_month"2020-06-01T00:00:00.000000+00:00"
"2020-06-01T01:30:45.000000+00:00".beginning_of_month"2020-06-01T00:00:00.000000+00:00"

beginning_of_year

Returns first day of the year for a given date/datetime.

Syntax

Date.beginning_of_year

  • Date - An input date or datetime.

Sample usage

FormulaResult
today.beginning_of_year"2020-01-01T00:00:00.000000+00:00"
"2020-06-01".to_date.beginning_of_year"2020-01-01T00:00:00.000000+00:00"
"2020-06-01T01:30:45.000000+00:00".beginning_of_year"2020-01-01T00:00:00.000000+00:00"

end_of_month

Returns last day of the month for a given date/datetime. This formula will return a date or datetime based on the input data.

Syntax

Date.end_of_month

  • Date - An input date or datetime.

Sample usage

FormulaResult
today.end_of_month"2020-12-31"
"2020-06-01".to_date.end_of_month"2020-06-30"
"2020-06-01T01:30:45.000000+00:00".to_time.end_of_month"2020-06-30T23:59:59.999999+00:00"

strftime

Returns a datetime input as a user-defined string.

Syntax

Date.strftime(format)

  • Date - An input date or datetime.
  • format - The format of the user-defined datetime written as a string.

Sample usage

FormulaResult
"2020-06-05T17:13:27.000000-07:00".to_date.strftime("%Y/%m/%d")"2020/06/05"
"2020-06-05T17:13:27.000000-07:00".strftime("%Y-%m-%dT%H:%M:%S%z")"2020-06-05T17:13:27-0700"
"2020-06-05T17:13:27.000000-07:00".strftime("%B %e, %l:%M%p")"June 5, 5:13 pm"
"2020-06-05T17:13:27.000000-07:00".strftime("%A, %d %B %Y %k:%M")"Friday, 05 June 2020 0:00"

Parameters

As previously shown, each code (%B, %e, %I, for example) refers to a specific element of datetime. You can also add static text and punctuation, such as commas (,), slashes (/), and colons (:). Refer to the following list of frequently used codes:

CodeMeaningExample
(2020-06-05T17:13:27.000000-07:00)
%YYear with century2020
%mMonth with zero-prefix06
%BFull month nameJune
%bAbbreviated month nameJun
%dDay of the month with zero-prefix05
%eDay of the month without zero-prefix5
%HHour of the day (24-hour)17
%kHour of day without 0 prefix (24-hour)17
%I (capital i)Hour of the day (12-hour)05
%l (lowercase L)Hour of day without 0 prefix (12-hour)5
%pAM or PMPM
%MMinute of the hour13
%SSecond of the minute27
%LMillisecond of the second000
%zTime zone offset from UTC-0700
%😒Time zone formatted offset from UTC-07:00
%ZTime zone abbrev. nameUTC
%AFull day nameFriday

To access the full list, check out the Ruby documentation

How it works

Allows the user to define a datetime format. Returns the datetime input in the specified format.

Input datatype

The input must be a date or datetime datatype. You can use the to_date formula to convert a string into a date datatype.

See also

  • to_date: Returns a date in date datatype.

in_time_zone

Converts a date or datetime to a different time zone using IANA time zone names. Returns a datetime.

Syntax

Date.in_time_zone(timezone)

  • Date - An input date or datetime.
  • timezone - The target timezone name (optional). Refer to Regions reference for valid timezone names.

Behavior

The formula behaves differently depending on how you call it:

  • No argument - Returns Pacific Time: now.in_time_zone
  • Timezone specified - Converts to the specified timezone: now.in_time_zone("America/New_York")
  • Explicit nil - Returns UTC timezone: now.in_time_zone(nil)

Sample usage

FormulaResult
today.in_time_zone("America/New_York")"2020-12-01T00:00:00.000000-05:00"
today.to_time.in_time_zone("America/New_York")"2020-11-30T19:00:00.000000-05:00"
"2020-06-01".to_time.in_time_zone"2020-05-31T17:00:00.000000-07:00"
"2020-06-01T01:30:45.000000+00:00".in_time_zone"2020-05-31T18:30:45.000000-07:00"
"2020-06-01T01:30:45.000000-07:00".in_time_zone(nil)"2020-06-01T08:30:45.000000+00:00"

dst?

Returns true if the input datetime is within Daylight Savings Time.

Syntax

Datetime.dst?

  • Datetime - An input date or datetime.

Sample usage

FormulaResult
today.to_time.dst?false
today.in_time_zone("America/New_York").dst?true
"2020-06-01".in_time_zone("America/New_York").dst?true
"2020-09-06T18:30:15.671720-05:00".to_time.dst?false

Regions reference

Refer to the following table for the timezone name to use in the formula.

RegionTimezone to use in formulaUTC zoneDST offset?
International Date Line WestPacific/MidwayUTC-11
Midway IslandPacific/MidwayUTC-11
American SamoaPacific/Pago_PagoUTC-11
HawaiiPacific/HonoluluUTC-10
AlaskaAmerica/JuneauUTC-9
Pacific Time (US & Canada)America/Los_AngelesUTC-8
TijuanaAmerica/TijuanaUTC-8
Mountain Time (US & Canada)America/DenverUTC-7
ArizonaAmerica/PhoenixUTC-7
ChihuahuaAmerica/ChihuahuaUTC-7
MazatlanAmerica/MazatlanUTC-7
Central Time (US & Canada)America/ChicagoUTC-6
SaskatchewanAmerica/ReginaUTC-6
GuadalajaraAmerica/Mexico_CityUTC-6
Mexico CityAmerica/Mexico_CityUTC-6
MonterreyAmerica/MonterreyUTC-6
Central AmericaAmerica/GuatemalaUTC-6
Eastern Time (US & Canada)America/New_YorkUTC-5
Indiana (East)America/Indiana/IndianapolisUTC-5
BogotaAmerica/BogotaUTC-5
LimaAmerica/LimaUTC-5
QuitoAmerica/LimaUTC-5
Atlantic Time (Canada)America/HalifaxUTC-4
CaracasAmerica/CaracasUTC-4
La PazAmerica/La_PazUTC-4
SantiagoAmerica/SantiagoUTC-4
GeorgetownAmerica/GuyanaUTC-4
NewfoundlandAmerica/St_JohnsUTC-3:30
BrasiliaAmerica/Sao_PauloUTC-3
Buenos AiresAmerica/Argentina/Buenos_AiresUTC-3
MontevideoAmerica/MontevideoUTC-3
GreenlandAmerica/GodthabUTC-3
Mid-AtlanticAtlantic/South_GeorgiaUTC-2
AzoresAtlantic/AzoresUTC-1
Cape Verde Is.Atlantic/Cape_VerdeUTC-1
DublinEurope/DublinUTC-1
LisbonEurope/LisbonUTC+0
EdinburghEurope/LondonUTC+0
LondonEurope/LondonUTC+0
MonroviaAfrica/MonroviaUTC+0
UTCEtc/UTCUTC+0
CasablancaAfrica/CasablancaUTC+1
BelgradeEurope/BelgradeUTC+1
BratislavaEurope/BratislavaUTC+1
BudapestEurope/BudapestUTC+1
LjubljanaEurope/LjubljanaUTC+1
PragueEurope/PragueUTC+1
SarajevoEurope/SarajevoUTC+1
SkopjeEurope/SkopjeUTC+1
WarsawEurope/WarsawUTC+1
ZagrebEurope/ZagrebUTC+1
BrusselsEurope/BrusselsUTC+1
CopenhagenEurope/CopenhagenUTC+1
MadridEurope/MadridUTC+1
ParisEurope/ParisUTC+1
AmsterdamEurope/AmsterdamUTC+1
BerlinEurope/BerlinUTC+1
BernEurope/ZurichUTC+1
ZurichEurope/ZurichUTC+1
RomeEurope/RomeUTC+1
StockholmEurope/StockholmUTC+1
ViennaEurope/ViennaUTC+1
West Central AfricaAfrica/AlgiersUTC+1
BucharestEurope/BucharestUTC+2
CairoAfrica/CairoUTC+2
HelsinkiEurope/HelsinkiUTC+2
KyivEurope/KievUTC+2
RigaEurope/RigaUTC+2
SofiaEurope/SofiaUTC+2
TallinnEurope/TallinnUTC+2
VilniusEurope/VilniusUTC+2
AthensEurope/AthensUTC+2
JerusalemAsia/JerusalemUTC+2
HarareAfrica/HarareUTC+2
PretoriaAfrica/JohannesburgUTC+2
KaliningradEurope/KaliningradUTC+2
IstanbulEurope/IstanbulUTC+3
MinskEurope/MinskUTC+3
MoscowEurope/MoscowUTC+3
St. PetersburgEurope/MoscowUTC+3
KuwaitAsia/KuwaitUTC+3
RiyadhAsia/RiyadhUTC+3
NairobiAfrica/NairobiUTC+3
BaghdadAsia/BaghdadUTC+3
TehranAsia/TehranUTC+3:30
VolgogradEurope/VolgogradUTC+4
SamaraEurope/SamaraUTC+4
Abu DhabiAsia/MuscatUTC+4
MuscatAsia/MuscatUTC+4
BakuAsia/BakuUTC+4
TbilisiAsia/TbilisiUTC+4
YerevanAsia/YerevanUTC+4
KabulAsia/KabulUTC+4:30
EkaterinburgAsia/YekaterinburgUTC+5
IslamabadAsia/KarachiUTC+5
KarachiAsia/KarachiUTC+5
TashkentAsia/TashkentUTC+5
Sri JayawardenepuraAsia/ColomboUTC+5:30
ChennaiAsia/KolkataUTC+5:30
KolkataAsia/KolkataUTC+5:30
MumbaiAsia/KolkataUTC+5:30
New DelhiAsia/KolkataUTC+5:30
KathmanduAsia/KathmanduUTC+5:45
AstanaAsia/DhakaUTC+6
DhakaAsia/DhakaUTC+6
AlmatyAsia/AlmatyUTC+6
UrumqiAsia/UrumqiUTC+6
RangoonAsia/RangoonUTC+6:30
NovosibirskAsia/NovosibirskUTC+7
BangkokAsia/BangkokUTC+7
HanoiAsia/BangkokUTC+7
JakartaAsia/JakartaUTC+7
KrasnoyarskAsia/KrasnoyarskUTC+7
BeijingAsia/ShanghaiUTC+8
ChongqingAsia/ChongqingUTC+8
Hong KongAsia/Hong_KongUTC+8
Kuala LumpurAsia/Kuala_LumpurUTC+8
SingaporeAsia/SingaporeUTC+8
TaipeiAsia/TaipeiUTC+8
PerthAustralia/PerthUTC+8
IrkutskAsia/IrkutskUTC+8
UlaanbaatarAsia/UlaanbaatarUTC+8
SeoulAsia/SeoulUTC+9
OsakaAsia/TokyoUTC+9
SapporoAsia/TokyoUTC+9
TokyoAsia/TokyoUTC+9
YakutskAsia/YakutskUTC+9
DarwinAustralia/DarwinUTC+9:30
AdelaideAustralia/AdelaideUTC+9:30
CanberraAustralia/MelbourneUTC+10
MelbourneAustralia/MelbourneUTC+10
SydneyAustralia/SydneyUTC+10
BrisbaneAustralia/BrisbaneUTC+10
HobartAustralia/HobartUTC+10
VladivostokAsia/VladivostokUTC+10
GuamPacific/GuamUTC+10
Port MoresbyPacific/Port_MoresbyUTC+10
MagadanAsia/MagadanUTC+11
SrednekolymskAsia/SrednekolymskUTC+11
Solomon Is.Pacific/GuadalcanalUTC+11
New CaledoniaPacific/NoumeaUTC+11
FijiPacific/FijiUTC+12
KamchatkaAsia/KamchatkaUTC+12
Marshall Is.Pacific/MajuroUTC+12
AucklandPacific/AucklandUTC+12
WellingtonPacific/AucklandUTC+12
Nuku'alofaPacific/TongatapuUTC+13
Tokelau Is.Pacific/FakaofoUTC+13
SamoaPacific/ApiaUTC+13
Chatham Is.Pacific/ChathamUTC+13:45

to_date

This formula converts input data into a date and returns the date formatted as YYYY-MM-DD.

Syntax

String.to_date(format: format)

  • String - A string input that describes a date or datetime.
  • format - (optional) The format of the input date string. If not specified, Workato parses the input string automatically.

FORMAT PARAMETER DOESN'T AFFECT OUTPUT FORMAT

The format parameter defines only the input format. It does not affect the output format, which is always returned as YYYY-MM-DD.

Sample usage

FormulaResult
"23-01-2020 10:30 pm".to_date(format: "DD-MM-YYYY")"2020-01-23"
"01-23-2020 10:30 pm".to_date(format: "MM-DD-YYYY")"2020-01-23"
"2020/01/23".to_date(format: "YYYY/MM/DD")"2020-01-23"
"06/27/25".to_date(format: "%m/%d/%y")"2025-06-27"

How it works

Converts the input data into a date datatype.

INPUT DATA BEST PRACTICE

We recommend that you specify the input data format. If you don't specify the input data format, Workato parses the input string automatically.

The input string must resemble a date for this formula to work.

See also

  • strftime: Returns datetime is a custom format.
  • to_time: Converts a string to an ISO timestamp.

to_time

Converts a string to an ISO timestamp. The response will use the UTC timezone (+00:00).

Syntax

String.to_time(format: format)

  • String - An input string that describes a date or datetime.
  • format - (optional) The format of the user-defined datetime written as a string.

Sample usage

FormulaResult
"2020-04-02T12:30:30.462659-07:00".to_time(format: "%Y-%m-%dT%H:%M:%S")"2020-04-02T19:30:30.000+00:00"
"2020-04-02".to_time"2020-04-02T00:00:00.000+00:00"

How it works

Converts the input string into a datetime datatype. The output datetime will be converted to the UTC timezone (+00:00).

Autofill time

If the input data does not include the time, the output will default to 00:00:00.000000 +00:00.

See also

  • strftime: Returns datetime is a custom format.
  • to_date: This formula converts the date-like input into a date. Returns the date formatted as YYYY-MM-DD.

Parameters

As previously shown, each code (%B, %e, %I, for example) refers to a specific element of datetime. You can also add static text and punctuation, such as commas (,), slashes (/), and colons (:). Refer to the following list of frequently used codes:

CodeMeaningExample
(2020-06-05T17:13:27.000000-07:00)
%YYear with century2020
%mMonth with zero-prefix06
%BFull month nameJune
%bAbbreviated month nameJun
%dDay of the month with zero-prefix05
%eDay of the month without zero-prefix5
%HHour of the day (24-hour)17
%kHour of day without 0 prefix (24-hour)17
%I (capital i)Hour of the day (12-hour)05
%l (lowercase L)Hour of day without 0 prefix (12-hour)5
%pAM or PMPM
%MMinute of the hour13
%SSecond of the minute27
%LMillisecond of the second000
%zTime zone offset from UTC-0700
%😒Time zone formatted offset from UTC-07:00
%ZTime zone abbrev. nameUTC
%AFull day nameFriday

To access the full list, check out the Ruby documentation


to_i

Convert datetime into epoch time. Returns an epoch time in UTC (+00:00).

Syntax

Datetime.to_i

  • Datetime - An input datetime.

Sample usage

FormulaResult
today.to_time.to_i1645660800
now.to_i1645714000

How it works

Converts the input datetime into an integer, it will return epoch time in seconds, not milliseconds. The output datetime will be converted to the UTC timezone (+00:00).

Converting between Epoch time to datetime

Convert time formats easily with Workato formulas.

How to convert human readable time to epoch time

Use to_i to convert a datetime datapill to epoch time (in UTC). Learn more about how it works.

How to convert epoch time to human-readable time

Use the following formula to convert an epoch time to human-readable datetime.

Note that the output will be in UTC timezone (+00:00).

"1970-01-01".to_time + Epoch time.seconds

If you plan to convert epoch time to a specific timezone, you must specify it with in_time_zone.

"1970-01-01".to_time.in_time_zone("US/Pacific") + Epoch time.seconds

Wrong datatype: undefined method to_i

Epoch time requires a datetime datapill. If you are using a date datapill, it will cause an error.

Use to_time to convert a date into a datetime before converting to epoch time.

See also

  • to_time: Converts a string to an ISO timestamp.
  • to_date: This formula converts the date-like input into a date. Returns the date formatted as YYYY-MM-DD.
  • in_time_zone: Converts a time value to a different time zone.

Last updated: