Skip to main content
Version: Next

strftime

Function

strftime format time values

Synopsis

strftime(format: string, t: time) -> string

Description

The strftime function returns a string representation of time t as specified by the provided string format. format is a string containing format directives that dictate how the time string is formatted.

These directives are supported:

DirectiveExplanationExample
%AWeekday as full nameSunday, Monday, ..., Saturday
%aWeekday as abbreviated nameSun, Mon, ..., Sat
%BMonth as full nameJanuary, February, ..., December
%bMonth as abbreviated nameJan, Feb, ..., Dec
%CCentury number (year / 100) as a 2-digit integer20
%cLocale's appropriate date and time representationTue Jul 30 14:30:15 2024
%DEquivalent to %m/%d/%y7/30/24
%dDay of the month as a zero-padded decimal number01, 02, ..., 31
%eDay of the month as a decimal number (1-31); single digits are preceded by a blank1, 2, ..., 31
%FEquivalent to %Y-%m-%d2024-07-30
%HHour (24-hour clock) as a zero-padded decimal number00, 01, ..., 23
%IHour (12-hour clock) as a zero-padded decimal number00, 01, ..., 12
%jDay of the year as a zero-padded decimal number001, 002, ..., 366
%kHour (24-hour clock) as a decimal number; single digits are preceded by a blank0, 1, ..., 23
%lHour (12-hour clock) as a decimal number; single digits are preceded by a blank0, 1, ..., 12
%MMinute as a zero-padded decimal number00, 01, ..., 59
%mMonth as a zero-padded decimal number01, 02, ..., 12
%nNewline character\n
%p"ante meridiem" (a.m.) or "post meridiem" (p.m.)AM, PM
%REquivalent to %H:%M18:49
%rEquivalent to %I:%M:%S %p06:50:58 PM
%SSecond as a zero-padded decimal number00, 01, ..., 59
%TEquivalent to %H:%M:%S18:50:58
%tTab character\t
%UWeek number of the year (Sunday as the first day of the week)00, 01, ..., 53
%uWeekday as a decimal number, range 1 to 7, with Monday being 11, 2, ..., 7
%VWeek number of the year (Monday as the first day of the week) as a decimal number (01-53)01, 02, ..., 53
%vEquivalent to %e-%b-%Y31-Jul-2024
%WWeek number of the year (Monday as the first day of the week)00, 01, ..., 53
%wWeekday as a decimal number, range 0 to 6, with Sunday being 00, 1, ..., 6
%XLocale's appropriate time representation14:30:15
%xLocale's appropriate date representation07/30/24
%YYear with century as a decimal number2024
%yYear without century as a decimal number24, 23
%ZTimezone nameUTC
%z+hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC)+0000
%%A literal '%' character%

Examples

Print the year number as a string

echo 2024-07-30T20:05:15.118252Z | zq -z 'strftime("%Y", this)' -

=>

"2024"

Print a date in European format with slashes

echo 2024-07-30T20:05:15.118252Z | zq -z 'strftime("%d/%m/%Y", this)' -

=>

"30/07/2024"