Functions to create and modify dates and date times
Functions
date(year, month, day, hour, minute, second) → {datetime}
Returns a new datetime from the specified year, month, day, hour, minute and second
Parameters:
Name | Type | Description |
---|---|---|
year |
int |
Required. The year of the date |
month |
int |
Required. The month of the date |
day |
int |
Required. The day of the date |
hour |
int |
Optional. The hour of the datetime in 24 hour time |
minute |
int |
Optional. The minutes of the datetime |
second |
int |
Optional. The seconds of the datetime |
Returns:
- Type:
- datetime
The datetime specified by the year, month, day at 12:00AM or the time specified by hour, minutes, seconds
Examples
// returns the datetime 24/03/2020 12:00
date(2020, 3, 24)
// returns the datetime 24/03/2020 5:15:20 PM
date(2020, 3, 24, 17, 15, 20)
date_add(datetime, interval, unit) → {datetime}
The date_add() function adds a time/date interval to a datetime and then returns the datetime.
Parameters:
Name | Type | Description |
---|---|---|
datetime |
datetime |
Required. The datetime to add the interval to |
interval |
int |
Required. The interval amount, this can be negative to subtract the time/date interval |
unit |
string |
Required. The interval unit. Possible unit values are: 'year', 'month', 'day', 'hour', 'minute' and 'second' |
Returns:
- Type:
- datetime
Returns specified datetime plus the time/date interval
Examples
// if mydate is 24/03/2020 17:24 this returns 27/03/2020 17:24
date_add(mydate, 3, 'day')
// if mydate is 24/03/2020 17:24 this returns 24/12/2019 17:24
date_add(my_date, (0 - 3), 'month')
date_diff(datetime1, datetime2, unit) → {datetime}
The date_diff() function returns the difference between 2 date times in the given unit. If datetime2 is greater than datetime1 a negative number will be returned. Only whole units are returned
Parameters:
Name | Type | Description |
---|---|---|
datetime1 |
datetime |
Required. A datetime |
datetime2 |
datetime |
Required. A datetime |
unit |
string |
Required. The unit. Possible unit values are: 'year', 'month', 'day', 'hour', 'minute' and 'second' |
Returns:
- Type:
- datetime
Returns the difference in units between datetime1 and datetime2
date_trunc(datetime, precision) → {datetime}
The date_trunc() function is used to truncate a datetime to a specified precision.
Parameters:
Name | Type | Description |
---|---|---|
datetime |
datetime |
Required. The datetime to truncate |
precision |
string |
Required. The precision to truncate the datetime to. Possible values are: 'year', 'month' and 'day' |
Returns:
- Type:
- datetime
Returns specified datetime truncated to the specified precision
Examples
// if mydate is 24/03/2020 17:24 this returns 27/03/2020 12:00
date_trunc(mydate, 'day')
// if mydate is 24/03/2020 17:24 this returns 01/03/2019 12:00
date_trunc(my_date, 'month')
now() → {datetime}
The now() function returns the current date and time.
Returns:
- Type:
- datetime
Returns the current date and time
today() → {datetime}
The today() function returns the current date with the time at 12:00AM.
Returns:
- Type:
- datetime
Returns the current date at 12:00AM