- CURRENT_DATE: The CURRENT_DATE function returns the current date in ‘yyyy-MM-dd’ format. The syntax for the CURRENT_DATE function is as follows
CURRENT_DATE
For example:
SELECT CURRENT_DATE; — Returns ‘2023-03-04’ (assuming today’s date is March 4, 2023)
- CURRENT_TIMESTAMP: The CURRENT_TIMESTAMP function returns the current timestamp in ‘yyyy-MM-dd HH:mm:ss’ format.
The syntax for the CURRENT_TIMESTAMP function is as follows:
CURRENT_TIMESTAMP
For example:
SELECT CURRENT_TIMESTAMP; — Returns ‘2023-03-04 12:34:56’ (assuming the current time is 12:34:56)
You can also use the FROM_UNIXTIME function to convert a Unix timestamp to a date or timestamp string. For example:
SELECT FROM_UNIXTIME(1646448000); — Returns ‘2022-03-04 00:00:00’ (assuming the Unix timestamp represents March 4, 2022)
Note that the Unix timestamp is the number of seconds since January 1, 1970.