CURRENT TIME FUNCTIONS

current_date

Returns the current date as a value in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

SELECT CURDATE();
        -> '2011-02-13'
SELECT CURDATE() + 0;
        -> 20110213

now()

NOW returns the current date and time. The return value will be expressed as ‘YYYY-MM-DD HH:MM:SS:mmmmmm’ or YYYYMMDDHHMMSS.uuuuuu, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone (Drizzle timezone is always UTC).

SELECT NOW();
        -> '2011-02-15 13:40:06:002203'
SELECT NOW() + 0;
        -> 20110215134006.002203

NOW returns a constant time that indicates the time at which the statement began to execute.

SELECT NOW(), SLEEP(2), NOW();

Returns:

NOW() SLEEP(2) NOW()
2011-02-20 20:15:09:002203 0 2011-02-20 20:15:09:002203

SYSDATE, however, returns the exact time at which the function was invoked.

SELECT SYSDATE(), SLEEP(2), SYSDATE();

Returns:

SYSDATE() SLEEP(2) SYSDATE()
2011-02-20 20:15:09 0 2011-02-20 20:15:11

When using replication, the binary log will include SET TIMESTAMP entries so that a database can be restored from the binary log. In doing this, values from NOW will be adjusted to the same times as when the original SQL statements were executed. SYSDATE entries will be unaffected by SET TIMESTAMP entries.

current_timestamp

See now()

CURRENT_TIMESTAMP() is a synonym for NOW().

localtime

See now()

LOCALTIME() is a synonym for NOW().

localtimestamp

See now()

LOCALTIMESTAMP() is a synonym for NOW().

Table Of Contents

Previous topic

Date and Time Functions

Next topic

EXTRACT DATE FUNCTION

This Page