SQLite strftime() Function
The SQLite strftime() function outputs a specified time value corresponding the specified time value and modifiers in the specified format.
Syntax
Here is the syntax of the SQLite strftime() function:
strftime(format, time_value [, modifier, modifier, ...])
Parameters
format
- time_value
- 
Optional. A time value. The time value can be in any of the following formats, as shown below. The value is usually a string, but in the case of format 12 it can be an integer or a floating point number. - YYYY-MM-DD
- YYYY-MM-DD HH:MM
- YYYY-MM-DD HH:MM:SS
- YYYY-MM-DD HH:MM:SS.SSS
- YYYY-MM-DDTHH:MM
- YYYY-MM-DDTHH:MM:SS
- YYYY-MM-DDTHH:MM:SS.SSS
- HH:MM
- HH:MM:SS
- HH:MM:SS.SSS
- now- the current date and time
- DDDDDDDDDD.dddddd- Julian days number with fractional part
 
- modifier
- 
Optional. You can use zero or more modifiers to change the time value time_value. Multiple modifiers are applied sequentially from left to right. You can use modifiers like this:- NNN days- Add- NNNdays to the time value
- NNN hours- Add- NNNhours to the time value
- NNN minutes- Add- NNNminutes to the time value
- NNN.NNNN seconds- Add- NNN.NNNNseconds to the time value
- NNN months- Add- NNNmonths to the time value
- NNN years- Add- NNNyears to the time value
- start of month- Fall back to the beginning of the month in- time_value
- start of year- Fall back to the beginning of the year in- time_value
- start of day- Fall back to the beginning of the day in- time_value
- weekday N- Advance- time_valueββto weekday- N
- unixepoch- Unix timestamp for now
- julianday- The Julian calendar days for now
- auto
- localtime- The current time
- utc- The utc time
 The NNNrepresents a number. Can be a positive or negative number. IfNNNis negative, it means subtraction.
Return value
The SQLite strftime() function returns a string in the specified format. If no arguments are provided, the strftime() function returns the current date.
If you don’t provide the format argument , the strftime() function will return NULL.
All other date or time functions can be implemented using the strftime() function:
- strftime('%Y-%m-%d', ...)is equivalent to- date(...).
- strftime('%H:%M:%S', ...)is equivalent to- time(...).
- strftime('%Y-%m-%d %H:%M:%S', ...)is equivalent to- datetime(...).
- strftime('%J', ...) -- note-1is equivalent to- julianday(...), except that- julianday(...)returns a number.
- strftime('%s', ...) -- note-1is equivalent to- unixepoch(...), except that- unixepoch(...)returnes an integer.
Examples
Here are some examples to show usages of the SQLite strftime() function.
- 
Get the current date using the SQLite strftime()function:SELECT strftime('%Y-%m-%d'), strftime('%Y-%m-%d', 'now');strftime('%Y-%m-%d') strftime('%Y-%m-%d', 'now') -------------------- --------------------------- 2022-07-26 2022-07-26
- 
Use SQLite strftime()function to get current datetime:SELECT strftime('%Y-%m-%d %H:%M:%S'), strftime('%Y-%m-%d %H:%M:%S', 'now');strftime('%Y-%m-%d %H:%M:%S') strftime('%Y-%m-%d %H:%M:%S', 'now') ----------------------------- ------------------------------------ 2022-07-26 08:47:26 2022-07-26 08:47:26
- 
Get the current time using the SQLite strftime()function:SELECT strftime('%H:%M:%S'), strftime('%H:%M:%S', 'now');strftime('%H:%M:%S') strftime('%H:%M:%S', 'now') -------------------- --------------------------- 08:48:40 08:48:40
- 
Use the SQLite strftime()function to get the Unix timestamp of the current time:SELECT strftime('%s'), strftime('%s', 'now');strftime('%s') strftime('%s', 'now') -------------- --------------------- 1658825364 1658825364
- 
Get the current date using the SQLite strftime()function:SELECT strftime('%Y-%m-%d', 'now', 'start of year', '1 year', '-1 day');strftime('%Y-%m-%d', 'now', 'start of year', '1 year', '-1 d ------------------------------------------------------------ 2022-12-31