mysql 查詢時間轉換 Mysql 查詢時間轉換

2021-10-18 11:42:30 字數 884 閱讀 3537

利用data_format函式:

select date_format(now(),'%y-%m-%d ');

根據format字串格式化date值:

%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 兩位數字表示的年份 %% 直接值「%」

MySQL查詢時間函式

今天是 select now 2015 09 28 13 48 12 查詢當天,格式為yyyy mm dd select curdate 2015 09 28 查詢當天,格式為yyyy mm dd hh mm ss select now 2015 09 28 13 42 00 查詢當天0點,格式為y...

mysql查詢時間總結

當天 select from order where to days 輸入時間欄位名 to days 輸入時間欄位名 昨天select from order where to days now to days 輸入時間欄位名 1 7天select from order where date sub ...

mysql查詢時間範圍

前端傳入的引數確是 yyyy mm dd 的 沒有帶時分秒。如果按照下面這兩種方式會查不全 select from test where create time between 2018 07 30 and 2018 07 31 select from test where create time ...