Mysql 日期時間格式化

2021-09-08 11:01:05 字數 1120 閱讀 1412

1、日期轉成指定格式:date_format(date, format)

2、int型時間轉成指定格式:from_unixtime(unix_timestamp,format)

根據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日期時間格式化引數

mysql中常常會用到對日期的格式化,比如按某時間格式計算間隔,按某時間格式統計資訊等等,所以整理了一下日期格式化的引數,可以根據自己的需求進行組合使用。使用例子如下 1 select date format now y m d h i s 2 select date format 2018 10 ...

Mysql 格式化日期格式

date format date,format 根據格式串format 格式化日期或日期和時間值date,返回結果串。可用date format 來格式化date 或datetime 值,以便得到所希望的格式。根據format字串格式化date值 s,s 兩位數字形式的秒 00,01,59 i 兩位...

mysql日期格式化

定義和用法 date format 函式用於以不同的格式顯示日期 時間資料。語法date format date,format 格式 描述 a 縮寫星期名 b 縮寫月名 c 月,數值 d 帶有英文本首的月中的天 d 月的天,數值 00 31 e 月的天,數值 0 31 f 微秒 h 小時 00 23...