sqliteHow do I store and retrieve datetime values in SQLite?
SQLite provides several functions to store and retrieve datetime values.
The strftime() function can be used to store datetime values in a SQLite database. It takes a datetime value and a format string as arguments and returns a string containing the formatted date and time. For example:
SELECT strftime('%Y-%m-%d %H:%M:%S', 'now');
2020-08-18 11:08:30
The date() function can be used to retrieve datetime values from a SQLite database. It takes a string containing a formatted date and time and returns a datetime value. For example:
SELECT date('2020-08-18 11:08:30');
2020-08-18 11:08:30
Code explanation
strftime()- Function used to store datetime values in a SQLite database.'now'- Datetime value used as argument for thestrftime()function.'%Y-%m-%d %H:%M:%S'- Format string used as argument for thestrftime()function.date()- Function used to retrieve datetime values from a SQLite database.'2020-08-18 11:08:30'- String containing a formatted date and time used as argument for thedate()function.
Helpful links
More of Sqlite
- How do I use the SQLite ZIP VFS to compress a database?
- How to configure SQLite with XAMPP on Windows?
- How do I extract the year from a datetime value in SQLite?
- How can I use SQLite with Xamarin Forms and C#?
- How do I use the SQLite Workbench?
- How do I call sqlitepcl.raw.setprovider() when using SQLite?
- How do I resolve an error "no such column" when using SQLite?
- How do I use SQLite keywords to query a database?
- How do I use SQLite xfilter to filter data?
- How can I use SQLite with WPF?
See more codes...