SQL set time format

SELECT STR_TO_DATE('Jul 20 2013 7:49:14:610AM','%b %d %Y %h:%i:%s:%f%p') from DUAL;

-- The result after execution:
'2013-07-20 07:49:14.610000'

In addition, there are cases where int values ​​and time variables are converted to each other:

 

SELECT UNIX_TIMESTAMP(2009-4-5 12:50:58) RROM DUAL;
-- The result is:
1238907058

SELECT FROM_UNIXTIME(1238907058) FROM DUAL;
-- The result is:
'2009-4-5 12:50:58'

 

 

You can also customize the output format:

SELECT FROM_UNIXTIME( 1234567890, '%Y-%m-%d %H:%i:%S' ) FROM DUAL;
--结果为:
'2009-02-14 07:31:30'

The specific format symbols are as follows:

 

%W week name (Sunday...Saturday)
%D day of the month with an English prefix (1st, 2nd, 3rd, etc.)
%Y year, number, 4 digits
%y year, number, 2 digits
%a abbreviated Week Name (Sun…Sat)
%d Number of days in month, numbers (00…31)
%e Number of days in month, numbers (0…31)
%m months, numbers (01…12)
%c months , Number (1…12)
%b Abbreviated month name (Jan…Dec)
%j Day of the year (001…366)
%H Hour (00…23)
%k Hour (0…23 )
%h hour (01…12)
%I hour (01…12)
%l hour (1…12)
%i minute, number (00…59)
%r time, 12 hour (hh:mm: ss [AP]M)
%T time, 24 hours (hh:mm:ss)
%S seconds (00...59)
%s seconds (00...59)
%f milliseconds (000...999)
%p AM or PM
%w day of the week (0=Sunday...6=Saturday)
%U week (0...52), where Sunday is the first day of the week
%u week (0...52), here Monday is the first day of the week
%% a literal "%".

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325253580&siteId=291194637