Skip to main content
Scripting

Date, time & timezones

Read, format and set dates in automations, and avoid timezone surprises in your scripts.

Datetime format​

Automations use the same date and time formats as the Tape API:

FormatShapeExample
DatetimeYYYY-MM-DD HH:mm:ss2023-02-01 15:00:00
DateYYYY-MM-DD2023-02-01
TimeHH:mm:ss15:00:00

These strings have no Z suffix and no offset. The variable name tells you the timezone: a name that ends in _utc holds UTC, the same name without _utc holds the same moment in the timezone of the automation.

Variables​

Each date field gives you several variables, named after the record name of the app, then field and the field name. Example: an app named Tasks with the record name Task has a date field named Date, with time and without an end date:

VariableDescriptionExample value
task_field_date_start_timeTime in the timezone of the automation.15:00:00
task_field_date_start_time_utcSame time in UTC.14:00:00
task_field_date_start_dateDate in the timezone of the automation.2023-02-01
task_field_date_start_date_utcSame date in UTC. Can be a different day than the local date near midnight.2023-02-01
task_field_date_formattedDate and time as one display string in the timezone of the automation, without seconds. Leaves out the time for a whole day.2023-02-01 15:00
What about whole-day values?

If the date field holds a whole day and no time, both _start_time variables are null. The local date and the _utc date are the same, because Tape doesn't convert a calendar day between timezones. See Calendar days.

Use the UTC values when you set or update field values, as Timezones explains.

Formatting dates​

Use the built-in date_fns library to format dates. Call its format function:

date_fns.format(new Date(task_field_date_start_date), 'y') // the year

Test your format strings in the interactive date-fns playground.

Timezones​

Automations run in UTC, and Tape's built-in actions handle this for you. Example: an action that copies a date from one record to another keeps the date and time people see in Tape.

Take care when you set dates in code, for example in Perform a calculation or Execute a script. The script reads every date string as UTC.

Example: a user in Amsterdam (UTC+1 in winter) wants to set a date field to 15:00 local time:

var_target_datetime = new Date('2023-02-01 15:00');

The script reads 2023-02-01 15:00 as 15:00 UTC. After the record update, the user sees 16:00 instead of 15:00.

Convert the local time to UTC first with zonedTimeToUtc from date_fns_tz, and pass the timezone of the user:

var_target_datetime = date_fns_tz.zonedTimeToUtc(new Date('2023-02-01 15:00'), 'Europe/Amsterdam');

Now the record shows 1 February 2023, 15:00 in the user's timezone. To use the timezone of the automation instead, pass current_workflow_timezone.

An automation with this conversion looks like this:

The automation editor with a Perform a calculation action that runs date_fns_tz.zonedTimeToUtc and an Update the current record action that sets the date

Next steps​