Skip to main content

Using time variables

You can use time variables to define date and time formats using the strftime() and strptime() evaluation functions.

There are variables that produce dates, variables that produce times, and variables that produce both dates and times.

Date and time variables

The following table lists variables that produce both a date and a time.

VariableDescription
%cThe date and time in the current locale's format as defined by the server's operating system. For example, Mon Oct 3 14:45:00 2022 for US English on Linux.
%+The date and time with time zone in the current locale's format as defined by the server's operating system. For example, Mon Oct 3 14:45:00 PDT 2022 for US English on Linux.

Time variables

The following table lists variables that produce a time.

VariableDescription
%EzRepresents the timezone offset from UTC with a colon between hours and minutes. For example, -08:00 indicates 8 hours behind UTC.
%HHour (24-hour clock) as a decimal number. Hours are represented by the values 00 to 23. Leading zeros are accepted but not required.
%IHour (12-hour clock) with the hours represented by the values 01 to 12. Leading zeros are accepted but not required.
%kLike %H, the hour (24-hour clock) as a decimal number. Leading zeros are replaced by a space, for example, 0 to 23.
%MMinute as a decimal number. Minutes are represented by the values 00 to 59. Leading zeros are accepted but not required.
%NRepresents the nanosecond component of the time
%pAM or PM.
%QRepresents the millisecond component of the time.
%SSecond as a decimal number, for example, 00 to 59.
%sThe Unix Epoch Time timestamp, or the number of seconds since the Epoch: 1970-01-01 00:00:00 +0000 (UTC). (Example: 1609459200 is Fri Jan 1 00:00:00 2021)
%TThe time in 24-hour notation (%H:%M:%S). For example, 23:59:59.
%XThe time in the format for the current locale. For US English, the format for 9:30 AM is 9:30:00.
%ZThe timezone abbreviation. For example, PST for US Pacific Standard Time.
%zThe timezone offset from UTC, without a colon between hours and minutes: +hhmm or -hhmm. For example, for 8 hours behind UTC the value is -0800.
%%A literal % character.

Date variables

The following table lists variables that produce a date.

VariableDescription
%FEquivalent to %Y-%m-%d (the ISO 8601 date format).
%xThe date in the format of the current locale. For example, 7/16/2024 for US English.

Specifying days and weeks

The following table lists variables that produce values for days and weeks.

VariableDescription
%AFull weekday name. (e.g., Sunday, ..., Saturday)
%aAbbreviated weekday name. (e.g., Sun, ..., Sat)
%dDay of the month as a decimal number, including leading zeros. (e.g., 01 to 31)
%eLike %d, the day of the month as a decimal number, but a leading zero is replaced by a space. (e.g., 1 to 31)
%jDay of the year as a decimal number, including leading zeros. (e.g., 001 to 366)
%VWeek of the year as a decimal number. (e.g., 1 to 52)
%wWeekday as a decimal number. (0 = Sunday, ..., 6 = Saturday)

Specifying months

The following table lists variables that produce values for months.

VariableDescription
%bAbbreviated month name. (e.g., Jan, Feb, etc.)
%BFull month name. (e.g., January, February, etc.)
%mMonth as a decimal number. (e.g., 01 to 12). Leading zeros are accepted but not required.

Specifying year

The following table lists variables that produce values for years.

VariableDescription
%yYear as a decimal number, without the century. (e.g., 00 to 99). Leading zeros are accepted but not required.
%YYear as a decimal number with century. For example, 2023.

Examples

The following table shows the results of various time format strings:

Time Format StringResult
%Y-%m-%d2021-12-31
%y-%m-%d21-12-31
%b %d, %YFeb 11, 2022
%d %b '%y = %Y-%m-%d23 Apr '22 = 2022-04-23
%A, %B %d, %YMonday, October 3, 2022
%a, %b %d, %YMon, Oct 3, 2022
%H:%M:%S14:45:00
%I:%M %p02:45 PM
%Y-%m-%dT%H:%M:%S%z2022-10-03T14:45:00-0700
%j of %Y277 of 2022 (Day of the year of Year)