NOW()
SQL · Date Functions
Theory
NOW() is a function that returns the current date and time. In MySQL and PostgreSQL it is simply another name for CURRENT_TIMESTAMP, so SELECT NOW() and SELECT CURRENT_TIMESTAMP give the same kind of value. Unlike the standard keyword, NOW() is written with parentheses because it is a function call.
The idea is universal but the spelling is not. SQL Server uses GETDATE() or SYSDATETIME(), Oracle uses SYSDATE or SYSTIMESTAMP, and SQLite uses datetime('now'). In MySQL, NOW() returns the moment the statement started, so it is the same for every row in one query, while SYSDATE() returns the exact moment each call executes. A typical use is a sliding window such as 'logins in the last 24 hours': WHERE login_at >= NOW() - INTERVAL 1 DAY. If you want code that moves between databases easily, CURRENT_TIMESTAMP is the safer choice.
Why we use it
Developers coming from MySQL or PostgreSQL write NOW() out of habit because it is short and reads naturally. Knowing it equals CURRENT_TIMESTAMP, and what each database calls it, saves you from 'function does not exist' errors.
When to use it
Use NOW() in MySQL or PostgreSQL code for timestamps and rolling time windows. When writing SQL that must run on several databases, or on SQL Server and SQLite, use CURRENT_TIMESTAMP or the local equivalent instead.
How it works
- You need 'right now' as date + time
- Is the database MySQL or PostgreSQL? Yes: Write NOW(). No: Look up the local name.
- SQL Server: GETDATE(); Oracle: SYSDATE; SQLite: datetime('now')
- Combine with INTERVAL for windows like 'last 24 hours'
- Same idea, different spelling per database
Syntax
NOW()Example
SELECT NOW();Key points
- Not available in SQL Server (use GETDATE()) or SQLite (use datetime('now'))
- Great for timestamping inserts/updates
- Same value as CURRENT_TIMESTAMP in MySQL and PostgreSQL
- MySQL NOW() is fixed per statement; SYSDATE() changes during execution
- For portable SQL prefer CURRENT_TIMESTAMP