Skip to main content

Datetime functions

Studio has many functions for working with dates and times. You can use these to calculate durations, convert durations from one time unit to another, and display datetime values in different formats

Many datetime functions take or return a datetime object — see Working with datetime objects for guidance.

Index of datetime functions

addToDateTime

Adds a duration to a datetime object.

asDateTime

Converts the input value to a datetime object.

asDays

Converts a duration from seconds to days.

asHours

Converts a duration from seconds to hours.

asMilliseconds

Converts a duration from seconds to milliseconds.

asMinutes

Converts a duration from seconds to minutes.

asMonths

Converts a duration from seconds to months.

asWeeks

Converts a duration from seconds to weeks.

asYears

Converts a duration from seconds to years.

dateTimeDifference

Returns the absolute difference (in seconds) between two datetime objects.

day

Returns a number representing the day part of a datetime object.

durationAsList

Converts a duration given in seconds to a list of seven duration values.

formatDateTime

Formats a datetime object using a format pattern or locale.

formatDuration

Formats the input duration as a text string.

getCurrentTime

Returns a datetime object for the current date and time.

getTimeZone

Returns the timezone ID (or offset) for a datetime object.

hour

Returns a number representing the hours part of a datetime object.

isDateTime

Tests if the input string can be parsed to create a datetime object.

minute

Returns a number representing the minutes part of a datetime object.

month

Returns a number representing the month part of a datetime object.

monthAsNumber

Returns the number for the input month name — e.g. 3 for March.

now

Returns the current time. Deprecated — superseded by getCurrentTime.

numberAsMonth

Returns the month name for the input number — e.g. March for 3.

numberAsWeekday

Returns the weekday name for the input number — e.g. Tuesday for 2.

parseDateTime

Parses a string to create a datetime object.

parseDuration

Converts a duration string to a number representing the duration in seconds.

second

Returns a number representing the seconds part of a datetime object.

setTimeZone

Sets the timezone ID (or offset) for a datetime object.

sortDateTimes

Sorts datetime objects in chronological order.

sortDateTimesReverse

Sorts datetime objects in reverse-chronological order.

sortMonthNames

Sorts month names in order of calendar month.

subtractFromDateTime

Subtracts a duration from a datetime object.

today

Returns the current date. Deprecated — superseded by getCurrentTime.

translateTimeZone

Translates a datetime object into its equivalent in a different timezone.

weekdayAsNumber

Returns the number for the input weekday name — e.g. 2 for Tuesday.

year

Returns a number representing the year part of a datetime object.