mssqlserver字串日期互相轉換

2022-02-05 12:51:08 字數 3503 閱讀 5651

我們經常出於某種目的需要使用各種各樣的日期格式,當然我們可以使用字串操作來構造各種日期格式,

/*用convert是明確地轉換一資料型別表示到另乙個,對於dateadd等等日期函式

的引數不一定是日期格式,只要可以轉化即可,對於convert,字串和日期是

2種不同的格式,這點要注意,我們來看看乙個試驗:*/

print dateadd(dd,1,@str)

print dateadd(dd,1,@dt)

print convert (varchar(10),@str,120)

print convert (varchar(10),@dt,120)

/*aug 27 2005 12:00am --dataadd認為字串'2005-8-26'和日期'2005-8-26'是一樣

aug 27 2005 12:00am

2005-8-26 /*convert 認為字串'2005-8-26'和日期'2005-8-26'不一樣*/

2005-08-26 /*對於字串對應的日期格式失效*/

*/sql server中文版的預設的日期欄位datetime格式是yyyy-mm-dd thh:mm:ss.mmm例如:select getdate()2004-09-12 11:06:08.177整理了一下sql server裡面可能經常會用到的日期格式轉換方法:舉例如下:select convert(varchar, getdate(), 120 )2004-09-12 11:06:08

select convert(varchar(100), getdate(), 0): 05 16 2006 10:57am

select convert(varchar(100), getdate(), 1): 05/16/06

select convert(varchar(100), getdate(), 2): 06.05.16

select convert(varchar(100), getdate(), 3): 16/05/06

select convert(varchar(100), getdate(), 4): 16.05.06

select convert(varchar(100), getdate(), 5): 16-05-06

select convert(varchar(100), getdate(), 6): 16 05 06

select convert(varchar(100), getdate(), 7): 05 16, 06

select convert(varchar(100), getdate(), 8): 10:57:46

select convert(varchar(100), getdate(), 9): 05 16 2006 10:57:46:827am

select convert(varchar(100), getdate(), 10): 05-16-06

select convert(varchar(100), getdate(), 11): 06/05/16

select convert(varchar(100), getdate(), 12): 060516

select convert(varchar(100), getdate(), 13): 16 05 2006 10:57:46:937

select convert(varchar(100), getdate(), 14): 10:57:46:967

select convert(varchar(100), getdate(), 20): 2006-05-16 10:57:47

select convert(varchar(100), getdate(), 21): 2006-05-16 10:57:47.157

select convert(varchar(100), getdate(), 22): 05/16/06 10:57:47 am

select convert(varchar(100), getdate(), 23): 2006-05-16

select convert(varchar(100), getdate(), 24): 10:57:47

select convert(varchar(100), getdate(), 25): 2006-05-16 10:57:47.250

select convert(varchar(100), getdate(), 100): 05 16 2006 10:57am

select convert(varchar(100), getdate(), 101): 05/16/2006

select convert(varchar(100), getdate(), 102): 2006.05.16

select convert(varchar(100), getdate(), 103): 16/05/2006

select convert(varchar(100), getdate(), 104): 16.05.2006

select convert(varchar(100), getdate(), 105): 16-05-2006

select convert(varchar(100), getdate(), 106): 16 05 2006

select convert(varchar(100), getdate(), 107): 05 16, 2006

select convert(varchar(100), getdate(), 108): 10:57:49

select convert(varchar(100), getdate(), 109): 05 16 2006 10:57:49:437am

select convert(varchar(100), getdate(), 110): 05-16-2006

select convert(varchar(100), getdate(), 111): 2006/05/16

select convert(varchar(100), getdate(), 112): 20060516

select convert(varchar(100), getdate(), 113): 16 05 2006 10:57:49:513

select convert(varchar(100), getdate(), 114): 10:57:49:547

select convert(varchar(100), getdate(), 120): 2006-05-16 10:57:49

select convert(varchar(100), getdate(), 121): 2006-05-16 10:57:49.700

select convert(varchar(100), getdate(), 126): 2006-05-16t10:57:49.827

select convert(varchar(100), getdate(), 130): 18 ???? ?????? 1427 10:57:49:907am

select convert(varchar(100), getdate(), 131): 18/04/1427 10:57:49:920am

ORACLE in 字串,字串,字串

因為傳進來的引數是 字串,字串,字串,要實現in 字串,字串,字串 select from htl price p where p.hotel id 30073328 and p.able sale date between to date 2009 03 27 yyyy mm dd and to ...

字串,字串陣列,字串指標!!

字串 字元陣列實際上是一系列字元的集合,也就是 字串 string 字串陣列 在c語言中,沒有專門的字串變數,沒有string型別,通常就用乙個字元陣列來存放乙個字串。c語言規定,可以將字串直接賦值給字元陣列 在c語言中,字串總是以 0 作為串的結束符。上面的兩個字串,編譯器已經在末尾自動新增了 0...

字串物件python int 字串 字串物件

最近研究字串物件,稍微總結一下,以後繼續補充 如果我們須要把python的字串物件轉換為數整物件,我們須要用到int方法。比如 ainfo 222 print int ainfo 輸出的結果是222。然後我們檢視下ainfo在現的型別,通過type方法檢視下,發現是 而如果ainfo fefew22...