1. 程式人生 > >SQL server資料庫CONVERT時間轉換函式

SQL server資料庫CONVERT時間轉換函式

Select CONVERT(varchar(100), GETDATE(), 0) as "0",
CONVERT(varchar(100), GETDATE(), 1) as "1",
CONVERT(varchar(100), GETDATE(), 2) as "2",
CONVERT(varchar(100), GETDATE(), 3) as "3",
CONVERT(varchar(100), GETDATE(), 4) as "4",
CONVERT(varchar(100), GETDATE(), 5) as "5",
CONVERT(varchar(100), GETDATE(), 6) as "6",
CONVERT(varchar(100), GETDATE(), 7) as "7",
CONVERT(varchar(100), GETDATE(), 8) as "8",
CONVERT(varchar(100), GETDATE(), 9) as "9";

-- 15-19期間的都不是有效的樣式號
Select CONVERT(varchar(100), GETDATE(), 10) as "10",
CONVERT(varchar(100), GETDATE(), 11) as "11",
CONVERT(varchar(100), GETDATE(), 12) as "12",
CONVERT(varchar(100), GETDATE(), 13) as "13",
CONVERT(varchar(100), GETDATE(), 14) as "14",
CONVERT(varchar(100), GETDATE(), 20) as "20",
CONVERT(varchar(100), GETDATE(), 21) as "21",
CONVERT(varchar(100), GETDATE(), 22) as "22",
CONVERT(varchar(100), GETDATE(), 23) as "23",
CONVERT(varchar(100), GETDATE(), 24) as "24",
CONVERT(varchar(100), GETDATE(), 25) as "25";

-- 26~99不是有效的樣式號
Select CONVERT(varchar(100), GETDATE(), 100) as "100",
CONVERT(varchar(100), GETDATE(), 101) as "101",
CONVERT(varchar(100), GETDATE(), 102) as "102",
CONVERT(varchar(100), GETDATE(), 103) as "103",
CONVERT(varchar(100), GETDATE(), 104) as "104",
CONVERT(varchar(100), GETDATE(), 105) as "105",
CONVERT(varchar(100), GETDATE(), 106) as "106",
CONVERT(varchar(100), GETDATE(), 107) as "107",
CONVERT(varchar(100), GETDATE(), 108) as "108",
CONVERT(varchar(100), GETDATE(), 109) as "109",
CONVERT(varchar(100), GETDATE(), 110) as "110";

--中間跳過的數字不是有效樣式號
Select CONVERT(varchar(100), GETDATE(), 111) as "111",
CONVERT(varchar(100), GETDATE(), 112) as "112",
CONVERT(varchar(100), GETDATE(), 113) as "113",
CONVERT(varchar(100), GETDATE(), 114) as "114",
CONVERT(varchar(100), GETDATE(), 120) as "120",
CONVERT(varchar(100), GETDATE(), 126) as "126",
CONVERT(varchar(100), GETDATE(), 130) as "130",
CONVERT(varchar(100), GETDATE(), 131) as "131";