以下是我过去使用的所有格式:
select CONVERT(VARCHAR(19),GETDATE())
select CONVERT(VARCHAR(10),GETDATE(),10)
select CONVERT(VARCHAR(10),GETDATE(),110)
select CONVERT(VARCHAR(11),GETDATE(),6)
select CONVERT(VARCHAR(11),GETDATE(),106)
select CONVERT(VARCHAR(24),GETDATE(),113)
select CONVERT(VARCHAR(10),GETDATE(),101)
select CONVERT(VARCHAR(10),CAST(GETDATE() AS DATE), 101)
select CONVERT(VARCHAR(8), GETDATE(), 1)
select CONVERT(VARCHAR(10), GETDATE(), 101)
select CONVERT(VARCHAR(8), GETDATE(), 10)
select CONVERT(VARCHAR(10), GETDATE(), 110)
select CONVERT(VARCHAR(23), GETDATE(), 121)
select CONVERT(varchar(23), getdate()+0.20, 121)
select CONVERT(varchar(23), getdate()+0.20, 21)
select CONVERT(varchar(23), getdate()+0.20, 20)
select CONVERT(varchar(23), getdate()+0.20, 120)
select convert(varchar (10),CONVERT(varchar(23), getdate(), 120),110)
select datediff(week, dateadd(week, datediff(week, 0, dateadd(month, datediff(month, 0, getdate()), 0)), 0), getdate() - 1) + 1 ----- this shows the week of month - which week today's date is in the current month
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)-- format is mm/dd/yyyy hh:mm:ss
select CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' + SUBSTRING( convert(varchar, getdate(),108),1,5)-- format is mm/dd/yyyy hh:mm
select convert(varchar(10), GETDATE(), 101) + stuff(right(convert(varchar(26),GETDATE(),109 ),15 ),7,7,' ')-- format is mm/dd/yyyy hh:mm AM/PM
SELECT CONVERT(VARCHAR(10),GETDATE(),101) +' '+ SUBSTRING(CONVERT(VARCHAR(20), GETDATE(), 9), 13, 5) + ' ' + SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 9), 25, 2)-- format is mm/dd/yyyy hh:mm AM/PM
select convert(varchar(10), GETDATE(), 101) + right(convert(varchar(32),GETDATE(),100),8)
select CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' + RIGHT(CONVERT(VARCHAR, GETDATE(), 100), 7)
select convert(varchar,getDate(),120)
select convert(varchar(10),getDate(),120)
SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM
SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy
SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd
SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy
SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy
SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy
SELECT convert(varchar, getdate(), 106) -- dd mon yyyy
SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy
SELECT convert(varchar, getdate(), 108) -- hh:mm:ss
SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)
SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy
SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd
SELECT convert(varchar, getdate(), 112) -- yyyymmdd
SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm
SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)
SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)
SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm
SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm