MySQL Date Or Time Function Part-7

SYSDATE Function:- SYSDATE Function is used to return the current server date and time. The format of the date and time will be “YYYY-MM-DD HH:MM: SS” (string) or as YYYYMMDDHHMMSS (numeric).

Syntax:- SYSDATE()



Output:- 2023-02-14 10:16:56

TIME Function:- TIME Function is used for extracting the time part from a given date or date and time expression.

Syntax:- TIME(expression)


SELECT TIME(“2023-02-14 13:50:30”);

Output:- 13:50:30

TIME_FORMAT Function:- TIME_FORMAT Function is used for formatting the time in a specific format from a given date and time.

Syntax:- TIME_FORMAT(time, format)

The following format will be used either single or combination:-

%f For   Microseconds (000000 to 999999)

%H For  Hour (00 to 23)

%h For  Hour (00 to 12)

%I For   Hour (00 to 12)

%i For    Minutes (00 to 59)

%p For  AM or PM

%r For   Time in 12 hour AM or PM format (hh:mm:ss AM/PM)

%S For  Seconds (00 to 59)

%s For   Seconds (00 to 59)

%T For  Time in 24 hour format (hh:mm:ss)

Example:- SELECT TIME_FORMAT(“15:57:40”, “%h %i %s %p”);

Output:- 03 57 40 PM

TIME_TO_SEC Function:- TIME_TO_SEC Function is used for converting time value into seconds.

Syntax:- TIME_TO_SEC(time value)


SELECT TIME_TO_SEC(“14:41:37”);

Output:- 52897

TIMEDIFF Function:- TIMEDIFF Function is used for the difference between the Same format at two different times.

Syntax:- TIMEDIFF(time1, time2)


SELECT TIMEDIFF(“14:44:34”, “12:50:19”);



TIMESTAMP Function:- TIMESTAMP Function is used for returning the date-time value from a given date-time value. For a single argument, it returns the date or datetime expression and in the case of two arguments, It returns the sum of two argument date or datetime expression.

Syntax:- TIMESTAMP(expression) or TIMESTAMP(expression1, expression2)


SELECT TIMESTAMP(“2023-02-15”,  “14:53:42”);

Output:- 2023-02-15 14:53:42

SELECT TIMESTAMP(“2023-02-15”);

Output:- 2023-02-15 00:00:00

Share with:

Leave a Reply

Connect with: