The time_format() is a MySQL date/time function. The purpose of it is to format the time using a defined format_mask.

Format_mask refers to the timely application of the format. The choices are listed below.

%f Microseconds (000000 to 999999)
%H Hour (00 to 23 generally, but can be higher)
%h Hour (00 to 12)
%I Hour (00 to 12)
%i Minutes (00 to 59)
%p AM or PM
%r Time in 12 hour AM or PM format (hh:mm:ss AM/PM)
%S Seconds (00 to 59)
%s Seconds (00 to 59)
%T Time in 24 hour format (hh:mm:ss)

As you have noticed, %h and %I have no difference in the output. Similarly, you can either use %S or %s.

SELECT TIME_FORMAT(“19:30:10”, “%H.%i%p”);
Result: 19.30PM
SELECT TIME_FORMAT(“19:30:10”, “%H %i %s”);
Result: 19 30 10
SELECT TIME_FORMAT(“19:30:10”, “%h.%i%p”);
Result: 07.30PM
SELECT TIME_FORMAT(“19:30:10”, “%r”);
Result: 07:30:10 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s