MySQL NOW()
The NOW()
function returns the current date and time in the format 'YYYY-MM-DD HH:MM:SS'. It is useful for recording timestamps.
Examples
1. Getting the Current Date and Time
SELECT NOW() AS current_datetime;
Code Explanation: This query returns the current date and time.
2. Inserting a Timestamp
INSERT INTO tamil_kings_events (event_name, event_date) VALUES ('Coronation of Raja Raja Chola', NOW());
Code Explanation: This query inserts an event with the current timestamp.
Best Practices
- Use
NOW()
for logging events or recording the time of data entry. - Be mindful of the server’s time zone settings when using
NOW()
.
Key Takeaways
- The
NOW()
function returns the current date and time. - It is useful for timestamping events or records.