In SQLite, you can use the string "now"
with the datetime()
, date()
, time()
and strftime()
functions to get the current date and time. The strftime()
function allows the flexibility of specifying the format for the resulting date/time string whereas the other date/time functions simply return the string in the standard formatting. For example:
Get Current Date and Time
To get the current date and time in the "YYYY-MM-DD HH:MM:SS" format, you can do either of the following:
SELECT datetime('now'); SELECT strftime('%Y-%m-%d %H:%M:%S', 'now');
Get Current Date
To get the current date only (in the "YYYY-MM-DD" format), you can do either of the following:
SELECT date('now'); SELECT strftime('%Y-%m-%d', 'now');
Get Current Time
To get the current time only (in the "HH:MM:SS" format), you can do either of the following:
SELECT time('now'); SELECT strftime('%H:%M:%S', 'now');
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.