---
title: "gsql_ts_to_epoch_seconds()"
component: "gsql-ref"
version: "4.1"
module: "ddl-and-loading"
html_url: "/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch"
canonical_url: "https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch"
markdown_url: "https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch.md"
---

[View as HTML](https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch)

# 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 4.1.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()](https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch_legacy.md) and [gsql\_ts\_to\_epoch\_seconds\_signed()](https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch_signed.md).

## 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

| 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. |

> [!NOTE]
> 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()](https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch_legacy.md) or [gsql\_ts\_to\_epoch\_seconds\_signed()](https://www.tigergraph.com/docs/gsql-ref/4.1/ddl-and-loading/functions/token/gsql_ts_to_epoch_signed.md).
