0
0
SQLquery~5 mins

CURRENT_DATE and CURRENT_TIMESTAMP in SQL

Choose your learning style9 modes available
Introduction
CURRENT_DATE and CURRENT_TIMESTAMP help you get the current date or date and time from the database automatically.
When you want to record the date a user signed up.
When you need to know the exact time a transaction happened.
When filtering records created today.
When adding timestamps to logs or events.
When comparing dates to the current day.
Syntax
SQL
CURRENT_DATE
CURRENT_TIMESTAMP
CURRENT_DATE returns only the date (year-month-day).
CURRENT_TIMESTAMP returns date and time (year-month-day hour:minute:second).
Examples
Gets today's date without time.
SQL
SELECT CURRENT_DATE;
Gets current date and time.
SQL
SELECT CURRENT_TIMESTAMP;
Gets both current date and current timestamp in one query.
SQL
SELECT CURRENT_DATE, CURRENT_TIMESTAMP;
Sample Program
This query shows the current date and the current date with time.
SQL
SELECT CURRENT_DATE AS today_date, CURRENT_TIMESTAMP AS now_timestamp;
OutputSuccess
Important Notes
The exact output time depends on when you run the query.
CURRENT_TIMESTAMP includes hours, minutes, and seconds.
Use these functions to avoid manually entering dates and times.
Summary
CURRENT_DATE gives you just the date part.
CURRENT_TIMESTAMP gives you date and time.
Use them to get the current date/time from the database automatically.