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

  1. You need 'right now' as date + time
  2. Is the database MySQL or PostgreSQL? Yes: Write NOW(). No: Look up the local name.
  3. SQL Server: GETDATE(); Oracle: SYSDATE; SQLite: datetime('now')
  4. Combine with INTERVAL for windows like 'last 24 hours'
  5. Same idea, different spelling per database

Syntax

NOW()

Example

SELECT NOW();

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic