Skip to content

STRFTIME

STRFTIME(format, timestring, modifier, modifier, …)

Section titled “STRFTIME(format, timestring, modifier, modifier, …)”
  • format: This parameter defines the exact string layout for the result, including placeholders for components of the date/time such as %H for hour or %Y for year.
  • timestring: This parameter represents the initial date/time string to process. It can be a standard numerical date/time or refer to now for the current date/time.
  • modifier: This optional parameter modifies the output or input. Multiple modifiers can be used. For instance, ‘localtime’ converts the timestring to the local time zone before processing, and ‘utc’ converts it to UTC.
SELECT STRFTIME('%Y-%m-%d %H:%M:%S', 'now');
2021-12-08 10:15:25

In the provided example, STRFTIME function was used to format the current date and time (obtained by now) to the ‘Year-Month-Day Hour:Minute:Second’ format. The %Y represents a 4-digit year, %m is for a 2-digit month, %d for a 2-digit day, %H for a 2-digit hour (24-hour clock), %M is for a 2-digit minute, and %S is for a 2-digit second. Each format specifiers are surrounded by single quotes to denote that it is a single string argument passed to the STRFTIME function.