關於mysql資料庫日期格式化

2021-08-27 06:59:55 字數 1236 閱讀 4837

date_forma t(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 兩位數字表示的年份

%% 直接值「%」

select date_format(日期字段,』%y-%m-%d』) as 『日期』 from test

格式化資料庫日期

格式化資料庫日期。此 段將允許您輸入date引數。它將檢查date引數以檢視是否存在有效的時間部分。然後,它將格式化日期,使其無論在何處或如何使用都可以正常工作。public function formatdate byval vdtdate as date as string dim dtnull...

在MySQL資料庫中格式化日期

不同的資料庫格式化日期都有不同的方法。sql server資料庫應用convert 函式,在oracle資料庫中格式化日期應用to char 函式。這篇文章我們既不將sqlserver資料庫,也不講oracle資料庫,我們就來 一下mysql資料庫中格式化日期。在mysql資料庫中我們一般使用函式d...

資料庫日期函式格式化

sql server 中乙個非常強大的日期格式化函式 select convert varchar 100 getdate 0 05 16 2006 10 57am select convert varchar 100 getdate 1 05 16 06 select convert varcha...