sqlite
  1. sqlite-now

SQLite Date & Time - NOW()

SQLite provides support for storing and formatting date and time values. The NOW() function is a built-in SQLite function that returns the current system date and time.

Syntax

The syntax for using the NOW() function in SQLite is as follows:

SELECT NOW();

Example

Suppose we want to retrieve the current system date and time in SQLite. We can use the NOW() function as follows:

SELECT NOW();

Output

When executed, the query above will return the current date and time in the following format: YYYY-MM-DD HH:MM:SS

e.g., 2021-06-16 12:30:45.

Explanation

The NOW() function in SQLite returns the current system date and time. It can be used in a SELECT statement, along with other columns and tables, to return the current date and time as part of a result set.

Use

You can use the NOW() function in SQLite to add a timestamp to your database records, to record the exact time that an action or event occurred. This can be useful for tracking changes, recording log entries, or monitoring system behavior.

Important Points

  • The NOW() function returns the date and time in UTC (Coordinated Universal Time) format.
  • The output format can be changed using the date and time format functions available in SQLite.
  • The current date and time is calculated when the function is called. It will not change during the course of a single transaction.

Summary

In this tutorial, we learned about the NOW() function in SQLite, which allows you to retrieve the current system date and time. We saw an example of how to use the NOW() function in a SELECT statement to return the current date and time as part of a result set. It's important to note that the output format can be changed using the date and time format functions available in SQLite.

Published on: