TIME_FORMAT(time,format) : TIME_FORMAT « Date Time Functions « MySQL Tutorial

Home
MySQL Tutorial
1.Introduction
2.Select Query
3.Database
4.Table
5.Table Join
6.Subquery
7.Insert Update Delete
8.Logic Operator
9.View
10.Data Types
11.Procedure Function
12.Cursor
13.Trigger
14.Date Time Functions
15.Comparison Functions Operators
16.Aggregate Functions
17.Cast Functions Operators
18.Control Flow Functions
19.Encryption Compression Functions
20.Information Functions
21.Math Numeric Functions
22.Miscellaneous Functions
23.String Functions
24.Regular Expressions
25.Data Dictionary
26.MySQL Utilities
27.Privilege
MySQL Tutorial » Date Time Functions » TIME_FORMAT 
14.48.1.TIME_FORMAT(time,format)

The TIME_FORMAT function can display a time in almost any format.

TIME_FORMAT() can only be passed time information, or it will return a NULL result.

TIME_FORMAT Output Formats

format ParameterOutput Format
%r12-hour time (hh:mm:ss (AM|PM))
%T24-hour time (hh:mm:ss)
%YNumeric year, 4 digits
%yNumeric year, 2 digits
%mMonth with leading 0 (01, 02-12)
%cMonth without leading 0 (1, 2-12)
%MMonth name (January, February, and so on)
%bMonth name, abbreviated (Jan, Feb, and so on)
%DDay of the month with an English suffix (1st, 2nd, and so on)
%dDay of the month with leading 0 (00, 01, 02-31)
%eDay of the month without leading 0 (0, 1, 2-31)
%WWeekday name (Sunday, Monday, and so on)
%aWeekday name, abbreviated (Sun, Mon, and so on)
%HHour (00, 01-23)
%kHour (0, 1-23)
%hHour (01, 02-12)
%IHour (01, 02-12)
%lHour (1, 2-12)
%iMinutes (00, 01-59)
%SSeconds (00, 01-59)
%sSeconds (00, 01-59)
%PAM or PM
%UWeek number in the year,in which Sunday is the first day of the week
$uWeek number in the year,in which Monday is the first day of the week
%X & %VYear and week number, respectively,in which Sunday is the first day of the week
%x & %vYear and week number, respectively,in which Monday is the first day of the week
%jDay of year with leading 0's (001, 002-366)
%wWeekday number (0=Sunday, 1=Monday, and so on)
%%Literal %


mysql>
mysql>
mysql> SELECT TIME_FORMAT(NOW()'%H:%i:%s');
+--------------------------------+
| TIME_FORMAT(NOW()'%H:%i:%s') |
+--------------------------------+
18:58:25                       |
+--------------------------------+
row in set (0.02 sec)

mysql>
mysql>
14.48.TIME_FORMAT
14.48.1.TIME_FORMAT(time,format)
14.48.2.TIME_FORMAT(time,format): The format string may contain format specifiers only for hours, minutes, and seconds
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.