MySQL CURDATE()

The CURDATE() function returns the current date in the format 'YYYY-MM-DD'. It is useful for recording only the date part of a timestamp.

Examples

1. Getting the Current Date

SELECT CURDATE() AS current_date;

Code Explanation: This query returns the current date without the time component.

2. Filtering Records by Current Date

SELECT * FROM tamil_kings_events WHERE event_date = CURDATE();

Code Explanation: This query retrieves records from tamil_kings_events that occurred on the current date.

Best Practices

  • Use CURDATE() when you only need the date part and not the time.
  • Consider using NOW() if you need both date and time.

Key Takeaways

  • The CURDATE() function returns the current date.
  • It is useful for comparing or filtering date-only records.