Mysql 格式化日期格式

2022-05-12 22:08:49 字數 1726 閱讀 6607

date_format(date, format) 根據格式串format 格式化日期或日期和時間值date,返回結果串。

可用date_format( ) 來格式化date 或datetime 值,以便得到所希望的格式。根據format字串格式化date值:

%s, %s 兩位數字形式的秒( 00,01, . . ., 59)

%i 兩位數字形式的分( 00,01, . . ., 59)

%h 兩位數字形式的小時,24 小時(00,01, . . ., 23)

%h, %i 兩位數字形式的小時,12 小時(01,02, . . ., 12)

%k 數字形式的小時,24 小時(0,1, . . ., 23)

%l 數字形式的小時,12 小時(1, 2, . . ., 12)

%t 24 小時的時間形式(h h : m m : s s)

%r 12 小時的時間形式(hh:mm:ss am 或hh:mm:ss pm)

%p am 或p m

%w 一周中每一天的名稱( s u n d a y, monday, . . ., saturday)

%a 一周中每一天名稱的縮寫( sun, mon, . . ., sat)

%d 兩位數字表示月中的天數( 00, 01, . . ., 31)

%e 數字形式表示月中的天數( 1, 2, . . ., 31)

%d 英文本尾表示月中的天數( 1st, 2nd, 3rd, . . .)

%w 以數字形式表示週中的天數( 0 = s u n d a y, 1=monday, . . ., 6=saturday)

%j 以三位數字表示年中的天數( 001, 002, . . ., 366)

% u 周(0, 1, 52),其中sunday 為週中的第一天

%u 周(0, 1, 52),其中monday 為週中的第一天

%m 月名(j a n u a r y, february, . . ., december)

%b 縮寫的月名( j a n u a r y, february, . . ., december)

%m 兩位數字表示的月份( 01, 02, . . ., 12)

%c 數字表示的月份( 1, 2, . . ., 12)

%y 四位數字表示的年份

%y 兩位數字表示的年份

%% 直接值「%」

eg:select date_format(now(),'%y/%m/%d %h:%i:%s') as time;

mysql日期格式化

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

MySql日期格式化

date format date,format 根據format字串格式化date值。下列修飾符可以被用在format字串中 m 月名字 january december w 星期名字 sunday saturday d 有英語字首的月份的日期 1st,2nd,3rd,等等。y 年,數字,4 位 y...

MySQL 格式化日期

使用 date format get date,y m d 函式進行格式化。其中 get date 是需要擷取的欄位名 y m d 是格式化後的日期格式。select date format 1997 10 04 22 23 00 y m b d w a y m d h i s r t 結果 97 ...