Mysql conversion between time and the string

1. Time to String

The DATE_FORMAT (date, format string)

SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s');

2. String transfer time

STR_TO_DATE (string, log format)

SELECT STR_TO_DATE('2019-01-20 16:01:45', '%Y-%m-%d %H:%i:%s');

3. Time turn timestamp

select unix_timestamp(now());

4. The transfer stamp string

select unix_timestamp('2019-01-20');  

The timestamp to String

select from_unixtime(1451997924,'%Y-%d');

Date format is attached as follows:

% M month name (January ...... December)  
% W week name (Sunday ...... Saturday)  
% D dated January English prefix (1st, 2nd, 3rd, etc.) %  
In the Y-digital, four  
% y in digital, two  
% a abbreviated weekday name (Sun ...... Sat)  
the number of days in the month% d, digital (00 ...... 31)  
days of the month% e, numbers (0 ...... 31)  
% m month, digital (01 ...... 12)  
% c month, numbers (1 ...... 12)  
% b abbreviated month name (Jan ...... Dec)  
the number of days in the% j year (001 ...... 366)  
% H hour (00 ...... 23 is)  
% K h (0 ...... 23 is)  
% h H (01 ...... 12 is)  
% the I h (01 ...... 12 is)  
% L h (12 is ....... 1)  
% I min, numbers (00 ...... 59)  
% r time, 12 hours (HH: mm: SS [the AP] M)  
% T time, 24 hours (HH: mm: SS)  
% S seconds (00 ...... 59)  
% S seconds (00 ...... 59)  
% P AM PM or  
days of the week W% (0 = Saturday the Sunday = ....... 6) %  
the U-week (0 ...... 52), where the first day of the week is Sunday  
% U Week (0 ...... 52), where Monday is the first week 

 

Conclusion: Those difficult life experiences, have become our brave.

 

Buddha Department of bloggers: AlanLee

Blog address: http://www.cnblogs.com/AlanLee

This article from the blog parks, welcome to join the blog garden.

 

Guess you like

Origin www.cnblogs.com/AlanLee/p/11579808.html