DateTime

◷ Reading Time: 5 minutes

today

Returns the local date for today.

 today ()
Example: today () 
Result: 8/12/2020 12:00:00 AM

Returns today's date. Time will always be 12:00:00 AM.

todayUtc

Returns today’s date in Coordinated Universal Time (UTC).

 todayUtc ()
Example: todayUtc () 
Result: 7/12/2020 12:00:00 AM

Returns today's UTC date. Time will always be 12:00:00 AM.

now

Returns the local date and time now.

 now ()
Example: now () 
Result: 8/12/2020 10:11:22 AM

Returns today's date including the time.

nowUtc

Returns local date and time now based on Coordinated Universal Time (UTC).

 nowUtc ()
Example: nowUtc () 
Result: 7/12/2020 11:12:41 PM

Returns today's UTC date including the time.

date

Builds a local date and time with different components.

 date (year, month, day, hour, minute, second, millisecond)
  • year (Integer): Year of the date (Mandatory)
  • month (Integer): Month of the date (Mandatory)
  • day (Integer): Day of the date (Mandatory)
  • hour (Integer): Hour of the date (Optional)
  • minute (Integer): Minute of the date (Optional)
  • second (Integer): Second of the date (Optional)
  • millisecond (Integer): Millisecond of the date (Optional)
Example: date (2020, 10, 01, 10, 55, 52, 2) 
Result: 1/10/2020 10:55:52 AM
Example: date (2020, 10, 01, 21, 55, 52, 2) 
Result: 1/10/2020 9:55:52 PM
Example: date (2020, 10, 01) 
Result: 1/10/2020 12:00:00 AM

isDate

Validates a string can be formatted as a date

 isDate (value, formatter)
  • value (String): Value that presents a date (Mandatory)
  • formatted (String): Valid list of date and time formatter (Mandatory)
DateTime format specifier
Below is the list of formatters:

– year: y yy yyy yyyy
– month: M MM MMM MMMM
– day: d dd ddd dddd
– hour: h hh H HH
– minute: m mm
– second: s ss
– AM/PM: t tt

For example: MM/dd/YYYY shows the month, day and year separated with /
For more details, visit Format specifier
Example: isDate ('4/12/2020','d/MM/yyyy') 
Result: True
Example: isDate ('4/12/2020') 
Result: True
Example: isDate ('4/12/2020 12:00:00 AM','d/MM/yyyy hh:mm:ss tt') 
Result: True
Example: isDate ('4/12/2020 12:00:00 AM','d/MM/yyyy') 
Result: False

dateUtc

Builds a date and time with different components based on Coordinated Universal Time (UTC).

 dateUtc (year, month, day, hour, minute, second, millisecond)
  • year (Integer): Year of the date (Mandatory)
  • month (Integer): Month of the date (Mandatory)
  • day (Integer): Day of the date (Mandatory)
  • hour (Integer): Hour of the date (Optional)
  • minute (Integer): Minute of the date (Optional)
  • second (Integer): Second of the date (Optional)
  • millisecond (Integer): Millisecond of the date (Optional)
Example: dateUtc (2020, 10, 01, 10, 55, 52, 2) 
Result: 1/10/2020 10:55:52 AM
Example: dateUtc (2020, 10, 01, 21, 55, 52, 2) 
Result: 1/10/2020 9:55:52 PM
Example: dateUtc (2020, 10, 01) 
Result: 1/10/2020 12:00:00 AM

dateDiff

Returns the time between two dates based on an interval.

 dateDiff (interval, date1, date2)
  • interval (String): Years, months, weeks, days, hours, minutes, seconds, milliseconds, offset (Mandatory)
  • date1 (DateTime): Beginning date (Mandatory)
  • date2 (DateTime): End date (Mandatory)

dateDiff would calculate date1-date2 expression agnostically. When offset is selected for the interval, the result is an array of values for [days, hours, minutes, seconds, milliseconds] otherwise the value is a number.

Example: dateDiff ('years', #1/10/2019 12:00:00 AM#, #1/10/2018 12:00:00 AM#)
Result: 1
Example: dateDiff ('years', #1/10/2018 12:00:00 AM#, #1/10/2019 12:00:00 AM#)
Result: -1
Example: dateDiff ('months', today(), #1/10/2019 12:00:00 AM#)
Result: 14.2684931506849

Time difference in months beween today and 1/10/2019 12:00:00 AM 
Example: dateDiff ('offset', today(), #1/10/2020 12:00:00 AM#)

Result: 
[
     68,
     0,
     0,
     0,
     0
 ]

dateAdd

Adds a slot of time to a date based on an interval and returns the new date/time.

 dateAdd (interval, date, value)
  • interval (String): Years, months, days, hours, minutes, seconds, milliseconds (Mandatory)
  • date ( DateTime ): Beginning date (Mandatory)
  • value (Integer): Value to be added to the date (Mandatory)
Example: dateAdd ('years', #1/10/2019 12:00:00 AM#, 5) 
Result: 1/10/2024 12:00:00 AM
Example: dateAdd ('years', #1/10/2021#, -5) 
Result: 1/10/2016 12:00:00 AM
Example: dateAdd ('months', today(), 2) 
Result: 8/02/2021 12:00:00 AM

Adds 2 months to today's date
Updated on January 13, 2021

Was this article helpful?

Related Articles