SQL reference

Date and time formats

Percent format specifiers for strftime, strptime and try_strptime.

strftime formats temporal values. strptime parses text and fails on invalid input; try_strptime returns NULL instead. A list of formats can be tried in order where the overload accepts it.

SELECT strftime(ordered_at, '%Y-%m-%d %H:%M:%S');
SELECT try_strptime(raw_time, ['%Y-%m-%dT%H:%M:%S%z', '%Y-%m-%d']);

Specifiers

SpecifierMeaning
%a / %AAbbreviated / full weekday name
%b / %BAbbreviated / full month name
%cLocale-style date and time representation
%d / %-dZero-padded / unpadded day of month
%fFractional seconds in microseconds
%g / %GTwo-digit / four-digit ISO week-numbering year
%H / %-HZero-padded / unpadded 24-hour clock hour
%I / %-IZero-padded / unpadded 12-hour clock hour
%j / %-jZero-padded / unpadded day of year
%m / %-mZero-padded / unpadded month number
%M / %-MZero-padded / unpadded minute
%nNanoseconds where the input/parse target supports them
%pAM or PM marker
%S / %-SZero-padded / unpadded second
%uISO weekday number, Monday = 1
%UWeek number with Sunday as first weekday
%VISO week number
%wWeekday number, Sunday = 0
%WWeek number with Monday as first weekday
%xLocale-style date representation
%XLocale-style time representation
%y / %-yTwo-digit year
%YFour-digit year
%zNumeric UTC offset
%ZTime-zone name where available
%%Literal percent sign

Parsing guidance

  • Prefer ISO 8601 input with an explicit offset for instants.
  • Use TIMESTAMPTZ when parsed text represents an absolute instant and TIMESTAMP for local civil time.
  • A two-digit year is ambiguous across centuries; avoid it for durable data.
  • Locale-style formats are not a stable interchange contract.
  • Use try_strptime during staged ingestion, retain the original text and review rejected rows.
  • Formatting a timestamp without a time zone does not create an instant; the missing zone remains missing.

Vegalake, VegaDB and VegaFlow are trademarks or registered trademarks of Vegalake Inc.

On this page