Name

CURRENT_TIME()

Synopsis

CURRENT_TIME()

This function returns the current time in hh:mm:ss format. It will return the time in the hhmmss format (numeric format) if it’s used as part of a numeric calculation. The parentheses are not required. It’s synonymous with CURTIME(). Here is an example:

INSERT INTO appointments
(client_id, appt_date, start_time)
VALUES('1403', CURRENT_DATE( ), CURRENT_TIME);

In this example, we’re logging an unscheduled appointment that has just begun so that we can bill the client later. Of course, it’s easy enough to use one datetime column with the NOW() function for inserting data, and use other functions for extracting separate components later.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.