DateTimeToTimestamp (Azure Cosmos DB)

APPLIES TO: SQL API

Converts the specified DateTime to a timestamp.

Syntax

DateTimeToTimestamp (<DateTime>)

Arguments

DateTime
UTC date and time ISO 8601 string value in the format YYYY-MM-DDThh:mm:ss.fffffffZ where:

Format Description
YYYY four-digit year
MM two-digit month (01 = January, etc.)
DD two-digit day of month (01 through 31)
T signifier for beginning of time elements
hh two-digit hour (00 through 23)
mm two-digit minutes (00 through 59)
ss two-digit seconds (00 through 59)
.fffffff seven-digit fractional seconds
Z UTC (Coordinated Universal Time) designator

For more information on the ISO 8601 format, see ISO_8601

Return types

Returns a signed numeric value, the current number of milliseconds that have elapsed since the Unix epoch i.e. the number of milliseconds that have elapsed since 00:00:00 Thursday, 1 January 1970.

Remarks

DateTimeToTimestamp will return undefined if the DateTime value specified is invalid

Examples

The following example converts the DateTime to a timestamp:

SELECT DateTimeToTimestamp("2020-07-09T23:20:13.4575530Z") AS Timestamp
[
    {
        "Timestamp": 1594336813457
    }
]

Here's another example:

SELECT DateTimeToTimestamp("2020-07-09") AS Timestamp
[
    {
        "Timestamp": 1594252800000
    }
]

Next steps