// strings reference

SQL STRFTIME function

Formats an SQLite date or time value as a string using C-style % placeholders.

Category
Strings
Returns
string
In this category
110 of 172

Syntax

strftime(format, time_value [, modifier, ...])

Engine support

EngineSupportNotes
SQL Server Different name or syntax Use FORMAT(date, format) or CONVERT with a style.
PostgreSQL Different name or syntax Use TO_CHAR(timestamp, format).
MySQL Different name or syntax Use DATE_FORMAT(date, format).
SQLite Yes Supported under this name.
Oracle Different name or syntax Use TO_CHAR(date, format).

Examples

SQLite

SELECT strftime('%Y-%m-%d', 'now') AS today;

SQLite

SELECT strftime('%s', created_at) AS epoch
FROM events;

SQLite

SELECT strftime('%Y-%m-%d', created_at, 'start of month') AS month
FROM orders;

Good to know

  • Accepted inputs: 'YYYY-MM-DD', 'YYYY-MM-DD HH:MM[:SS[.SSS]]' with a space or a T, time-only 'HH:MM' forms, an optional timezone suffix, 'now', or a number (a Julian day, or Unix seconds with the 'unixepoch' modifier). Anything else, such as '20/11/2026', returns NULL.
  • Common placeholders: %Y %m %d %H %M %S, %s (Unix seconds), %j (day of year), %w (weekday, 0 = Sunday), %W (week of year, weeks starting Monday).
  • Modifiers apply left to right: strftime('%Y-%m-%d', 'now', '-1 day', 'start of month') takes yesterday, then the first of that month.

Questions about STRFTIME

How do I get a Unix timestamp in SQLite?

strftime('%s', value) returns seconds since 1970 as text. unixepoch(value), added in SQLite 3.38, returns it as an integer.

What is the MySQL equivalent of strftime?

DATE_FORMAT(date, '%Y-%m-%d') uses the same % idea, but the letters differ: minutes are %i in MySQL and %M in SQLite, where MySQL's %M is the month name.

Why does strftime return NULL on my datetime string?

The input is not in a format SQLite recognises. ISO forms with a space or T work; '20/11/2026' or 'Nov 20 2026' do not. Store dates as ISO-8601 text, Julian days or Unix seconds.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.