Date functions
27.5
Lesson

STRFTIME Function

Let’s say we just need the month part of the current timestamp.

STRFTIME is a SQL function that can be used over DATETIME to extract specific information. Look at the example below.

Let’s say we need the current hour. The query would look like this:

Here are a few basic parameters that you can use to extract specific datetime related information.

%d day of month: 00
%f fractional seconds: SS.SSS
%H hour: 00-24
%j day of year: 001-366
%J Julian day number
%m month: 01-12
%M minute: 00-59
%s seconds since 1970-01-01
%S seconds: 00-59
%w day of week 0-6 with Sunday==0
%W week of year: 00-53
%Y year: 0000-9999

You can also combine one or more date parameters to get information the way you need it. Suppose we want the time stamp in format DD/MM/YYYY HH:MM:SS. Look at the query below