sqliteHow do I extract the year from a datetime value in SQLite?
To extract the year from a datetime value in SQLite, you can use the strftime()
function. This function takes a datetime value as an argument and returns a string of the desired format. To extract the year, use the format specifier %Y
, which will return the year as a 4-digit integer.
For example:
SELECT strftime('%Y', '2020-01-01 10:00:00');
Output example
2020
The code above consists of the following parts:
SELECT
- specifies what should be returned from the querystrftime('%Y', '2020-01-01 10:00:00')
- thestrftime()
function, which takes a datetime value and returns the year as a 4-digit integer
Helpful links
More of Sqlite
- How to configure SQLite with XAMPP on Windows?
- How do I show the databases in SQLite?
- How do I use the SQLite sequence feature?
- How can SQLite and ZFS be used together for software development?
- How do I use SQLite with Visual Studio?
- How do I use SQLite to retrieve data from a specific year?
- How can I use an upsert statement to update data in a SQLite database?
- How do I use the SQLite SUBSTRING function?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I create a SQLite query using Xamarin?
See more codes...