πŸ• NOW() – Get the Current Date and Time in SQL

πŸ”§ Quick Syntax

SELECT NOW();

This tells SQL:

β€œGive me the exact date and time β€” right now, down to the second.”

It returns a timestamp in this format: YYYY-MM-DD HH:MM:SS


🧾 Suppose You Want to Record When a User Logged In

INSERT INTO logins (user_id, login_time)
VALUES (1, NOW());

This logs the exact date and time a user signed in. NOW() auto-generates the current timestamp.


βœ… Suppose You Just Want to See What Time It Is

SELECT NOW() AS current_time;

πŸ’‘ Output:

2025-04-14 16:32:10

This changes every time you run it β€” it’s always the current moment.


βœ… Combine NOW() with Other Columns

SELECT username, NOW() AS checked_at
FROM users;

This shows when each row was “checked” β€” great for logging, reporting, or exporting data with timestamps.


πŸ§ƒ Recap – What You Learned

  • NOW() returns the current date and time
  • Format: YYYY-MM-DD HH:MM:SS
  • Use it in SELECT, INSERT, UPDATE, etc.
  • Great for timestamps, logs, and real-time tracking

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top