9951 explained code solutions for 126 technologies


sqliteHow do I format a date in SQLite using the YYYYMMDD format?


To format a date in SQLite using the YYYYMMDD format, use the strftime function. The following example code block will return the current date in YYYYMMDD format:

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

Output example

20200831

The code above consists of two parts:

  1. strftime('%Y%m%d', 'now') - This is the strftime function, which takes two arguments. The first argument is the format string, which specifies how the date should be formatted. The second argument is the date to be formatted. In this case, the date is set to now, which will return the current date.
  2. SELECT - This keyword is used to query the database and return the result of the query.

Helpful links

Edit this code on GitHub