parseTimestamp
Description
Returns a parsed timestamp from a date or time string, enabling use of DataPrime's time functions.
Note
If the string cannot be parsed (for example, if it does not match the expected format), the function returns null.
Syntax
Like many functions in DataPrime, parseTimestamp supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| string | string | true | The string to parse into a timestamp |
| format | string | false | The format of the input string. Defaults to auto, which attempts to match against well-known formats. |
| tz | string | false | A valid time zone string |
Example 1
Use case: Parse a simple date string using default format
Example query
Example output
Example 2
Use case: Parse a US-style date
Example query
Example output
Example 3
Use case 3: Parse date and time with units
Example query
Example output
Example 4
Use case 4: Parse a Unix timestamp in seconds
Example query
Example output
Example 5
Use case 5: Parse inconsistent formats with multiple options
Some logs contain timestamps in different formats. Provide a |-separated list of formats to handle them all.
Example data
{ "ts": "1680710853123", "app": "app1" },
{ "ts": "2023-04-05", "app": "app2" },
{ "ts": "2023-04-05T16:07:33.123Z", "app": "app3" }
Example query
Example output
{ "ts": "1680710853123", "app": "app1", "ts_parsed": 1680710853123000000 },
{ "ts": "2023-04-05", "app": "app2", "ts_parsed": 1680652800000000000 },
{ "ts": "2023-04-05T16:07:33.123Z", "app": "app3", "ts_parsed": 1680710853123000000 }
Theme
Light