dateAdd()
Adds a specified time interval to a given date.
Syntax | dateAdd(<time>, <interval>, <unit>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The initial time | |
<interval> |
INT |
The number of units to add (positive value to add, negative to subtract) | |
<unit> |
STRING |
The unit of time to add, which can be year , month , day , hour , minute , or second |
|
Return Type | DATETIME |
return dateAdd("1970-1-1", -1, "hour") as newTime
Result:
newTime |
---|
1969-12-31 23:00:00 |
return dateAdd("1970-1-1", 10, "year")
Result:
newTime |
---|
1980-01-01 00:00:00 |
dateDiff()
Computes the difference between two dates (time1
- time2
) and returns the result as a specified unit of time.
Syntax | dateAdd(<time1>, <time2>, <unit>) |
||
Arguments | Name | Type | Description |
<endTime> |
Temporal | The first time | |
<time2> |
Temporal | The second time | |
<unit> |
STRING |
The unit of difference, which can be day , hour , minute , or second |
|
Return Type | DATETIME |
return dateDiff("1970-01-01 10:00:00", "1970-01-01 12:00:20", "minute") as diff
Result:
diff |
---|
-120 |
dateFormat()
Prints a given date in the specific format.
Syntax | dateFormat(<time>, <formatCode>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The input time | |
<formatCode> |
STRING |
The format code | |
Return Type | STRING |
Format codes:
Code |
Description |
Examples / Range |
---|---|---|
%a |
Abbreviated weekday name in the system language | (en_US) Sun, Mon |
%A |
Full weekday name in the system language | (en_US) Sunday, Monday |
%b |
Abbreviated month name in the system language | (en_US) Jan, Feb |
%B |
Full month name in the system language | (en_US) January, February |
%c |
Default date and time format in the system settings | Wed Jan 11 10:59:28 2023 |
%C |
Century number (year/100) in 2 digits | 00, 01, ..., 99 |
%d |
Day of the month (zero-padded) | 01, 02, ..., 31 |
%D |
Equivalent to %m/%d/%y |
01/11/23 |
%e |
Day of the month | 1, 2, ..., 31 |
%Ez |
Time zone | +08:00 |
%g |
Year without the century | 00, 01, ..., 99 |
%G |
Year in 4 digits | 0000, 0001, ..., 9999 |
%h |
Equivalent to %b |
See %b |
%H |
Hour using a 24-hour clock (zero-padded) | 00, 01, ..., 23 |
%I |
Hour using a 12-hour clock (zero-padded) | 01, 02, ..., 12 |
%j |
Day of the year (zero-padded) | 001, 002, ..., 366 |
%m |
Month of the year (zero-padded) | 01, 02, ..., 12 |
%M |
Minute (zero-padded) | 00, 01, ..., 59 |
%n |
Line break | |
%p |
Either 'AM' or 'PM' according to the given time value | (en_US) AM, PM |
%P |
Either 'am' or 'pm' according to the given time value | (en_US) am, pm |
%r |
Equivalent to %I/%M/%S %p |
01:49:23 AM |
%R |
Equivalent to %H:%M |
13:49 |
%S |
Second (zero-padded) | 00, 01, ..., 59 |
%t |
Tab | |
%T |
Equivalent to %H:%M:%S |
23:02:05 |
%u |
Day number of the week, Monday being 1 (Sunday being 1 in a Sun Solaris system) | 1, 2, ..., 7 |
%U |
Week number of the year (zero-padded), starting with the first Sunday as the first day of week 01 | 00, 01, ..., 53 |
%V |
Week number of year (zero-padded), with Monday as the first day of the week, week 01 is the first week that has at least 4 days in the current year | 01, 02, ..., 53 |
%W |
Week number of the year (zero-padded), starting with the first Monday as the first day of week 01 | 00, 01, ..., 53 |
%w |
Day number of the week, Sunday being 0 | 0, 1, ..., 6 |
%x |
Default date format in the system settings | 01/11/23 |
%X |
Default time format in the system settings | 06:38:45 |
%y |
Equivalent to %g |
See %g |
%Y |
Equivalent to %G |
See %G |
%z |
Offset from UTC in the format of ±HHMM[SS] |
+0000, -0400, +1030, ... |
%Z |
Name of the time zone | GMT, UTC, IST, CST, ... |
%% |
Character % | % |
return dateFormat("2010/9/25 6:12:30","%A %e %B, %G") as newFormat
Result:
newFormat |
---|
Saturday 25 September, 2010 |
day()
Extracts the day component from a given date.
Syntax | day(<time>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The input time | |
Return Type | UINT |
return day("2022-10-5")
Result:
day("2022-10-5") |
---|
5 |
dayOfWeek()
Returns a number (from 1
to 7
, where 1
= Sunday and 7
= Saturaday) representing the day of the week for a given date.
Syntax | dayOfWeek(<time>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The input time | |
Return Type | UINT |
return dayOfWeek("2024-12-5")
Result:
dayOfWeek("2024-12-5") |
---|
5 |
month()
Extracts the month component from a given date.
Syntax | month(<time>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The input time | |
Return Type | UINT |
return month("2022-10-5")
Result:
month("2022-10-5") |
---|
10 |
now()
Returns the current date and time in Coordinated Universal Time (UTC).
Syntax | now() |
Return Type | DATETIME |
now()
Result:
now() |
---|
2024-12-05 06:43:47.402538 |
year()
Extracts the year component from a given date.
Syntax | year(<time>) |
||
Arguments | Name | Type | Description |
<time> |
Temporal | The input time | |
Return Type | UINT |
return year("2022-10-5")
Result:
year("2022-10-5") |
---|
2022 |