/
Working with Timestamps in R

Working with Timestamps in R

The SF timestamp is formatted as UNIX timestamp with millisecond precision. For our R scripting engine, this looks like an ordinary numeric. To create a date object, use the following snippet:

as.POSIXct(timestamp/1000, origin = "1970-01-01", tz="Europe/Vienna")

To use a R date object outside of a script, define a script result variable with data type either "timestamp" or "string". Using "string" has the advantage of formatting the date-time object as you like but when using a timestamp the widget will adjust the representation to the displayed time frame. Use the following code snippets to correctly format the date-objects to meet the correct output format requirements:

String as output,

outputStringTimestamp = as.character(internalDateObject)

Timestamp as output,

outputTimestamp = as.numeric(internalDateObject) * 1000

Alternatively look at the lubridate package. It offers many functions for handling timestamps and datetime objects in very intuitive way, just remember that lubridate is also expecting a timestamp in seconds and not in milliseconds, so devide the timestamp you get from your data by 1000.

Related content

Working with Timestamps in Python
Working with Timestamps in Python
More like this
FAQ and Troubleshooting
FAQ and Troubleshooting
More like this
Time Zones
More like this
FAQ and Troubleshooting - Dashboards
FAQ and Troubleshooting - Dashboards
More like this
Applying zoom to global timestamp filter
Applying zoom to global timestamp filter
More like this
Details of the Script Editor
Details of the Script Editor
More like this