SQL 时间格式

  • Post author:
  • Post category:其他


获取sql不同时间格式,使用Convert()函数,常用的不多,示例为sqlserver数据库。

官网文档:

https://learn.microsoft.com/zh-cn/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver16

https://learn.microsoft.com

具体例子:

SELECT CONVERT(varchar(100), GETDATE(), 0)  04 12 2023  4:20PMSELECT CONVERT(varchar(100), GETDATE(), 1)  04/12/23SELECT CONVERT(varchar(100), GETDATE(), 2)  23.04.12SELECT CONVERT(varchar(100), GETDATE(), 3)  12/04/23SELECT CONVERT(varchar(100), GETDATE(), 4)  12.04.23SELECT CONVERT(varchar(100), GETDATE(), 5)  12-04-23SELECT CONVERT(varchar(100), GETDATE(), 6)  12 04 23SELECT CONVERT(varchar(100), GETDATE(), 7)  04 12, 23SELECT CONVERT(varchar(100), GETDATE(), 8)  16:20:47SELECT CONVERT(varchar(100), GETDATE(), 9)  04 12 2023  4:20:47:900PMSELECT CONVERT(varchar(100), GETDATE(), 10) 04-12-23SELECT CONVERT(varchar(100), GETDATE(), 11)  23/04/12SELECT CONVERT(varchar(100), GETDATE(), 12)  230412SELECT CONVERT(varchar(100), GETDATE(), 13)  12 04 2023 16:20:59:383SELECT CONVERT(varchar(100), GETDATE(), 14)  16:21:12:127SELECT CONVERT(varchar(100), GETDATE(), 20)  2023-04-12 16:21:12SELECT CONVERT(varchar(100), GETDATE(), 21)  2023-04-12 16:21:12.127SELECT CONVERT(varchar(100), GETDATE(), 22) 04/12/23  4:21:24 PMSELECT CONVERT(varchar(100), GETDATE(), 23) 2023-04-12SELECT CONVERT(varchar(100), GETDATE(), 24) 16:21:24SELECT CONVERT(varchar(100), GETDATE(), 25) 2023-04-12 16:21:24.167SELECT CONVERT(varchar(100), GETDATE(), 26) 2023-12-04 16:24:15.687SELECT CONVERT(varchar(100), GETDATE(), 27) 04-12-2023 16:24:43.563SELECT CONVERT(varchar(100), GETDATE(), 28) 04-2023-12 16:24:43.563SELECT CONVERT(varchar(100), GETDATE(), 29) 12-04-2023 16:24:43.563SELECT CONVERT(varchar(100), GETDATE(), 30) 12-2023-04 16:25:03.890SELECT CONVERT(varchar(100), GETDATE(), 31) 2023-12-04SELECT CONVERT(varchar(100), GETDATE(), 32) 04-12-2023SELECT CONVERT(varchar(100), GETDATE(), 33) 04-2023-12SELECT CONVERT(varchar(100), GETDATE(), 34) 12-04-2023SELECT CONVERT(varchar(100), GETDATE(), 35) 12-2023-04SELECT CONVERT(varchar(100), GETDATE(), 100) 04 12 2023  4:21PMSELECT CONVERT(varchar(100), GETDATE(), 101) 04/12/2023SELECT CONVERT(varchar(100), GETDATE(), 102) 2023.04.12SELECT CONVERT(varchar(100), GETDATE(), 103) 12/04/2023SELECT CONVERT(varchar(100), GETDATE(), 104) 12.04.2023SELECT CONVERT(varchar(100), GETDATE(), 105) 12-04-2023SELECT CONVERT(varchar(100), GETDATE(), 106) 12 04 2023SELECT CONVERT(varchar(100), GETDATE(), 107) 04 12, 2023SELECT CONVERT(varchar(100), GETDATE(), 108) 16:22:01SELECT CONVERT(varchar(100), GETDATE(), 109) 04 12 2023  4:22:01:710PMSELECT CONVERT(varchar(100), GETDATE(), 110) 04-12-2023SELECT CONVERT(varchar(100), GETDATE(), 111) 2023/04/12SELECT CONVERT(varchar(100), GETDATE(), 112) 20230412SELECT CONVERT(varchar(100), GETDATE(), 113)  12 04 2023 16:22:20:587SELECT CONVERT(varchar(100), GETDATE(), 114) 16:22:20:587SELECT CONVERT(varchar(100), GETDATE(), 120) 2023-04-12 16:22:20SELECT CONVERT(varchar(100), GETDATE(), 121) 2023-04-12 16:22:37.443SELECT CONVERT(varchar(100), GETDATE(), 126)  2023-04-12T16:22:37.443SELECT CONVERT(varchar(100), GETDATE(), 127) 2023-04-12T16:28:28.650SELECT CONVERT(varchar(100), GETDATE(), 130)  22 ????? 1444  4:22:37:443PMSELECT CONVERT(varchar(100), GETDATE(), 131)   22/09/1444  4:22:37:443PM