gsql_ts_to_epoch_seconds()

Converts a timestamp in canonical string format to Unix epoch time, which is the number of seconds since Jan 1, 1970 00:00.

In 3.10.4, two new timestamp conversion functions are available for loading jobs, offering different behaviors for date handling, especially for dates prior to 1970: gsql_ts_to_epoch_seconds_legacy() and gsql_ts_to_epoch_seconds_signed().

Syntax

gsql_ts_to_epoch_seconds(timestamp)

Parameters

timestamp

Required. The timestamp to convert to Unix epoch time. The timestamp parameter should be in one of the following formats:

  • "%Y-%m-%d %H:%M:%S"

  • "%Y/%m/%d %H:%M:%S"

  • "%Y-%m-%dT%H:%M:%S.000z"

    • Text after the dot . is ignored

Return type

UINT

  • Returns the number of seconds since 1970-01-01 00:00:00 for valid timestamps within the supported range.

  • Throws an exception if the timestamp is invalid or before 1970-01-01 00:00:00.

Example

gsql_ts_to_epoch_seconds("2022-06-30 22-08-28") -> 1656652105
Comparison of Timestamp Conversion Functions
Function Return type Supported Time Range Response to Invalid/Unsupported Datetimes Description

gsql_ts_to_epoch_seconds()

UINT

1970-01-01 00:00:00 to 9999-12-31 23:59:59

Throws exception

Converts a timestamp to Unix epoch time (from 1970 onwards).

gsql_ts_to_epoch_seconds_legacy()

uint64_t

1970-01-01 00:00:00 to 9999-12-31 23:59:59

Returns defaultTimestamp

Similar to gsql_ts_to_epoch_seconds(), but returns 0 for pre-1970 timestamps, maintaining backward compatibility.

gsql_ts_to_epoch_seconds_signed()

int64_t

0001-01-01 00:00:00 to 9999-12-31 23:59:59

Returns defaultTimestamp

Supports a full date range, including pre-1970 timestamps, and returns negative epoch values for those dates.

If you need to avoid exceptions for invalid or pre-1970 dates, or require support for historical dates, consider using gsql_ts_to_epoch_seconds_legacy() or gsql_ts_to_epoch_seconds_signed().