# Date and Time Functions

Date and time functions are used to perform operations on date and time type data.

# NOW

now(fsp)
1

Returns the current time in the YYYY-MM-DD HH:mm:ss format. If the fsp parameter is provided to specify fractional seconds precision from 0 to 6, the returned value includes the corresponding fraction of seconds.

# CURRENT_TIMESTAMP

current_time(fsp)
1

Synonym for the NOW function.

# LOCAL_TIME

local_time(fsp)
1

Synonym for the NOW function.

# LOCAL_TIMESTAMP

local_timestamp(fsp)
1

Synonym for the NOW function.

# CUR_DATE

cur_date()
1

Returns the current date in the YYYY-MM-DD format.

# CURRENT_DATE

current_date()
1

Synonym for the CUR_DATE function.

# CUR_TIME

cur_time()
1

Returns the current time in the HH:mm:ss format.

# CURRENT_TIME

current_time()
1

Synonym for the CUR_TIME function.

# FORMAT_TIME

format_time(time, format)
1

Formats the time according to the specified format and returns the formatted string.

# DATE_CALC

date_calc(date, duration)
1

Calculates the date based on the date and duration and returns the calculated date.

The duration represents a time interval and can be represented as a string using the following formats:

  • Nanoseconds (ns): Suffixed with "ns".
  • Microseconds (us or µs): Suffixed with "us" or "µs" (using U+00B5 micro symbol).
  • Milliseconds (ms): Suffixed with "ms".
  • Seconds (s): Suffixed with "s".
  • Minutes (m): Suffixed with "m".
  • Hours (h): Suffixed with "h".

It also supports combining these representations for more complex time intervals, for example, 1h30m represents 1 hour 30 minutes. Multiple time units can be combined without spaces.

To subtract a time interval, you can prepend a - sign before the duration.

For example, -1h30m represents subtracting 1 hour 30 minutes.

Here are some examples for the duration

date_calc('2019-01-01', '1h')
date_calc('2019-01-01', '1h30m')
date_calc('2019-01-01', '1h30m10s')
date_calc('2019-01-01', '1h30m10s100ms')
date_calc('2019-01-01', '1h30m10s100ms200us')
date_calc('2019-01-01', '1h30m10s100ms200us300ns')
1
2
3
4
5
6

# DATE_DIFF

date_diff(date1, date2)
1

Calculates the difference in days between date1 and date2 and returns the calculated difference.

# DAY_NAME

day_name(date)
1

Returns the name of the day of the week for the given date, such as Monday, Tuesday, etc.

# DAY_OF_MONTH

day_of_month(date)
1

Returns the day of the month for the given date.

# DAY

day(date)
1

Synonym for DAY_OF_MONTH.

# DAY_OF_WEEK

day_of_week(date)
1

Returns the day of the week for the given date, where Sunday is 1, Monday is 2, and so on.

# DAY_OF_YEAR

day_of_year(date)
1

Returns the day of the year for the given date.

# FROM_DAYS

from_days(days)
1

Converts the days value to a date and returns the converted date.

# FROM_UNIX_TIME

from_unix_time(unix_timestamp)
1

Converts the unix_timestamp value to a date and returns the converted date.

# HOUR

hour(date)
1

Returns the hour part of the given date.

# LAST_DAY

last_day(date)
1

Returns the last day of the month for the given date.

# MICROSECOND

microsecond(date)
1

Returns the microsecond part of the given date.

# MINUTE

minute(date)
1

Returns the minute part of the given date.

# MONTH

month(date)
1

Returns the month part of the given date.

# MONTH_NAME

month_name(date)
1

Returns the name of the month for the given date, such as January, February, etc.

# SECOND

second(date)
1

Returns the second part of the given date.