For the complete documentation index, see llms.txt. This page is also available as Markdown.

Working with Timestamps in Python

The SF timestamp is formatted as UNIX timestamp (UTC) with millisecond precision. For our Python scripting engine, this looks like an ordinary integer. To transform a single timestamp into a date object, use the following snippet:

import datetime as dt
from dateutil.tz import gettz
dt.datetime.fromtimestamp(timestamp / 1000).astimezone(gettz('Europe/Vienna'))

If you want to know more about datetime objects in Python, check out the documentation.

To use a Python date object outside 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,

outputString = pythonDateTimeObj.strftime('%Y-%m-%d %H:%M:%S')
#or
outputString = pythonDateTimeObj.isoformat()

Timestamp as output,

outputTimestamp = pythonDateTimeObj.timestamp() * 1000

Last updated