mysql日期轉(zhuǎn)換函數(shù)有:1、date_format();2、time_format();3、str_to_date();4、to_days();5、from_days();6、time_to_sec();7、sec_to_time()等。
本教程操作環(huán)境:windows7系統(tǒng)、mysql8版本、Dell G3電腦。
MySQL 日期轉(zhuǎn)換函數(shù)、時間轉(zhuǎn)換函數(shù)
1,MySQL Date/Time to Str(日期/時間轉(zhuǎn)換為字符串)函數(shù):date_format(date,format), time_format(time,format):
函數(shù):date_format(‘2008-08-08 22:23:01’, ‘%Y%m%d%H%i%s’)
結(jié)果:20080808222301
MySQL 日期、時間轉(zhuǎn)換函數(shù):date_format(date,format), time_format(time,format) 能夠把一個日期/時間轉(zhuǎn)換成各種各樣的字符串格式。它是 str_to_date(str,format) 函數(shù)的 一個逆轉(zhuǎn)換。
2,MySQL Str to Date (字符串轉(zhuǎn)換為日期)函數(shù):str_to_date(str, format):
select?str_to_date('08/09/2008',?'%m/%d/%Y');?--?2008-08-09 select?str_to_date('08/09/08'?,?'%m/%d/%y');?--?2008-08-09 select?str_to_date('08.09.2008',?'%m.%d.%Y');?--?2008-08-09 select?str_to_date('08:09:30',?'%h:%i:%s');?--?08:09:30 select?str_to_date('08.09.2008?08:09:30',?'%m.%d.%Y?%h:%i:%s');?--?2008-08-09?08:09:30
str_to_date(str,format) 轉(zhuǎn)換函數(shù),可以把一些雜亂無章的字符串轉(zhuǎn)換為日期格式。
3,MySQL (日期、天數(shù))轉(zhuǎn)換函數(shù):to_days(date), from_days(days):
select?to_days('0000-00-00');?--?0 select?to_days('2008-08-08');?--?733627
4,MySQL (時間、秒)轉(zhuǎn)換函數(shù):time_to_sec(time), sec_to_time(seconds):
select?time_to_sec('01:00:05');?--?3605 select?sec_to_time(3605);?--?'01:00:05'
5,MySQL 拼湊日期、時間函數(shù):makdedate(year,dayofyear), maketime(hour,minute,second):
select?makedate(2001,31);?--?'2001-01-31' select?makedate(2001,32);?--?'2001-02-01' select?maketime(12,15,30);?--?'12:15:30'
6,MySQL (Unix 時間戳、日期)轉(zhuǎn)換函數(shù):
unix_timestamp(), unix_timestamp(date), from_unixtime(unix_timestamp), from_unixtime(unix_timestamp,format)
【相關(guān)推薦:mysql視頻教程】