π§ 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