Updated on 2026-11-06 GMT+08:00

unix_timestamp

The unix_timestamp function is used to convert a date value to a numeric UNIX format date value.

The function returns the first ten digits of a normal UNIX format timestamp.

Syntax

unix_timestamp(string timestamp, string pattern)

Parameters

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

timestamp

No

DATE or STRING

The date value to be converted.

Formats:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

pattern

No

STRING

The target format.

When pattern is empty, the default format is yyyy-mm-dd hh:mi:ss.

The format is a combination of time units representing year, month, day, hour, minute, and second, along with any characters.

  • yyyy indicates year.
  • mm indicates month.
  • dd indicates day.
  • hh indicates hour.
  • mi indicates minute.
  • ss indicates second.

Return Values

Returns a value of type BIGINT.

  • If the timestamp value is NULL, NULL is returned.
  • When both timestamp and pattern are empty, the timestamp representing the number of seconds from 1970-01-01 00:00:00 to the present is returned.

Example Code

  • Returns 1692149997.
    select unix_timestamp('2023-08-16 09:39:57')
  • Assuming the current system time is 2023-08-16 10:23:16, returns 1692152596.
    select unix_timestamp();