SQL Date Functions
HarperDB utilizes Coordinated Universal Time (UTC) in all internal SQL operations. This means that date values passed into any of the functions below will be assumed to be in UTC or in a format that can be translated to UTC.
When parsing date values passed to SQL date functions in HDB, we first check for ISO 8601 formats, then for RFC 2822 date-time format and then fall back to new Date(date_string)if a known format is not found.
CURRENT_DATE()
Returns the current date in UTC in YYYY-MM-DD
String format.
CURRENT_TIME()
Returns the current time in UTC in HH:mm:ss.SSS
String format.
CURRENT_TIMESTAMP
Referencing this variable will evaluate as the current Unix Timestamp in milliseconds.
DATE([date_string])
Formats and returns the date_string argument in UTC in YYYY-MM-DDTHH:mm:ss.SSSZZ
String format.
If a date_string is not provided, the function will return the current UTC date/time value in the return format defined above.
DATE_ADD(date, value, interval)
Adds the defined amount of time to the date provided in UTC and returns the resulting Unix Timestamp in milliseconds. Accepted interval values: Either string value (key or shorthand) can be passed as the interval argument.
DATE_DIFF(date_1, date_2[, interval])
Returns the difference between the two date values passed based on the interval as a Number. If an interval is not provided, the function will return the difference value in milliseconds.
Accepted interval values:
years
months
weeks
days
hours
minutes
seconds
DATE_FORMAT(date, format)
Formats and returns a date value in the String format provided. Find more details on accepted format values in the moment.js docs.
DATE_SUB(date, value, interval)
Subtracts the defined amount of time from the date provided in UTC and returns the resulting Unix Timestamp in milliseconds. Accepted date_sub interval values- Either string value (key or shorthand) can be passed as the interval argument.
EXTRACT(date, date_part)
Extracts and returns the date_part requested as a String value. Accepted date_part values below show value returned for date = “2020-03-26T15:13:02.041+000”
GETDATE()
Returns the current Unix Timestamp in milliseconds.
GET_SERVER_TIME()
Returns the current date/time value based on the server’s timezone in YYYY-MM-DDTHH:mm:ss.SSSZZ
String format.
OFFSET_UTC(date, offset)
Returns the UTC date time value with the offset provided included in the return String value formatted as YYYY-MM-DDTHH:mm:ss.SSSZZ
. The offset argument will be added as minutes unless the value is less than 16 and greater than -16, in which case it will be treated as hours.
NOW()
Returns the current Unix Timestamp in milliseconds.
Last updated