-
Notifications
You must be signed in to change notification settings - Fork 1
Date functions
Returns the system's current date & time, with precision of milliseconds.
now()
Note: Also achievable using the alias:
sysdate()
Parses a string representing a date by trying different parse patterns, supporting RFC-3339, RFC-822 and a set of common ISO-8601 variations. This function can be the fastest choice when handling RFC-3339 dates. Also useful to convert from other formats when the parse pattern is heterogeneous or unknown.
str2date("2015-10-03T08:00:01.123Z")
Parses a string representing a date with user-defined pattern. This can be the fastest approach when the date format is known.
str2date("2015-10-03", "yyyy-MM-dd")
Note: This function also supports variable parse pattern arguments, so it will try each pattern specified until it finds one that converts the source string to a valid date.
Converts a date into string using the specified format.
date2str(date1, "yyyy-MM-dd'T'HH:mm:ssZZ")
Returns the number of days between two dates (or valid date representations as string).
daysBetween("2019-01-19T22:40:38.678912543Z", "2019-02-19T22:41:39.123Z") //result: 31.0
Returns a date corresponding to the last day of the month given a source date.
endOfMonth("2019-02-10T08:15:26.109Z") //result: "2019-02-28T23:59:59.999Z"
Returns 1 (true) if the given argument is a leap year, that is, an year with 366 days, or 0 (false) if not. This function accepts an year (Number), a Date or a valid date representation as string in RFC-3339 format.
isLeapYear("2020-02-20T22:41:39.123Z") //result: 1.0
Returns the year for a given date.
year("2017-03-11T20:15:00:123Z") //result: 2017.0
Returns the quarter of the year, for a given date, as a number from 1 to 4.
quarter("2017-03-11T20:15:00:123Z") //result: 1.0
Returns the month for a given date, a number starting from 1 (January) to 12 (December).
month("2017-03-11T20:15:00:123Z") //result: 3.0
Returns the ISO week number in the year for a given date. According to the standard, the first week of an year will be the first one with a minimum of 4 days, starting with Monday. This function accepts Dates or valid date representation as string in RFC-3339 format.
isoWeekNumber("2017-03-11T20:15:00:123Z") //result: 10.0
Returns the day of the week of a date, a number from 1 (Sunday) to 7 (Saturday).
weekday("2019-06-12T18:00:01:988Z") //result: 4.0
Returns the day of the month for a given date. The first day of the month is 1.
day("2017-03-11T20:15:00:123Z") //result: 11.0
Returns the hour of day, for a given date, as a number from 0 (12:00 AM) to 23 (11:00 PM).
hour("2017-03-11T20:15:00:123Z") //result: 20.0
Returns the minute within the hour, for a given date, as a number from 0 to 59.
minute("2017-03-11T20:15:00:123Z") //result: 15.0
Returns the second within the minute, for a given date, as a number from 0 to 59.
second("2017-03-11T20:15:00:123Z") //result: 0.0
Returns the milliseconds within the second, for a given date.
millisecond("2017-03-11T20:15:00:123Z") //result: 123.0
Returns the result from adding the number of days to a given date (or a valid string representation of date).
addDays("2017-03-11T20:15:00:123Z", 1) //result: "2017-03-12T20:15:00:123Z"
addDays("2017-03-11T20:15:00:123Z", -1) //result: "2017-03-10T20:15:00:123Z"
Note: There are also other similar functions available:
addWeeks
,addMonths
,addQuarters
,addYears
,addHours
,addMinutes
, andaddSeconds
.