赞
踩
date_format(date,format)
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d');
time_format(time,format)
SELECT time_format(NOW(), '%h:%i:%s');
str_to_date(str, format)
select str_to_date('08.09.2021 08:09:30', '%m.%d.%Y %h:%i:%s');
to_days(date)
select to_days('2021-09-08') -- 738406
select to_days('0000-00-00'); -- NULL
from_days(days)
select FROM_DAYS(738406); -- 2021-09-08
time_to_sec(time)
select time_to_sec('08:09:30'); -- 29370
sec_to_time(seconds)
select sec_to_time(29370); -- '08:09:30'
makdedate(year,dayofyear)
select makedate(2021,31); -- '2021-01-31'
select makedate(2021,32); -- '2021-02-01'
maketime(hour,minute,second)
select maketime(12,15,30); -- '12:15:30'
时间转时间戳
SELECT UNIX_TIMESTAMP(NOW());
时间戳转时间
SELECT FROM_UNIXTIME(1777773871);
%S, %s 两位数字形式的秒( 00,01, …, 59)
%I, %i 两位数字形式的分( 00,01, …, 59)
%H 两位数字形式的小时,24 小时(00,01, …, 23)
%h 两位数字形式的小时,12 小时(01,02, …, 12)
%k 数字形式的小时,24 小时(0,1, …, 23)
%l 数字形式的小时,12 小时(1, 2, …, 12)
%T 24 小时的时间形式(hh:mm:ss)
%r 12 小时的时间形式(hh:mm:ss AM 或hh:mm:ss PM)
%p AM或PM
%W 一周中每一天的名称(Sunday, Monday, …, Saturday)
%a 一周中每一天名称的缩写(Sun, Mon, …, Sat)
%d 两位数字表示月中的天数(00, 01,…, 31)
%e 数字形式表示月中的天数(1, 2, …, 31)
%D 英文后缀表示月中的天数(1st, 2nd, 3rd,…)
%w 以数字形式表示周中的天数( 0 = Sunday, 1=Monday, …, 6=Saturday)
%j 以三位数字表示年中的天数( 001, 002, …, 366)
%U 周(0, 1, 52),其中Sunday 为周中的第一天
%u 周(0, 1, 52),其中Monday 为周中的第一天
%M 月名(January, February, …, December)
%b 缩写的月名( January, February,…, December)
%m 两位数字表示的月份(01, 02, …, 12)
%c 数字表示的月份(1, 2, …, 12)
%Y 四位数字表示的年份
%y 两位数字表示的年份
%% 直接值“%”
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。