Section 9:95. Date Manipulation – Getting Current Date and Timestamp

  1. 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


For example:

SELECT CURRENT_DATE; — Returns ‘2023-03-04’ (assuming today’s date is March 4, 2023)

  1. 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:


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.

Share this post