I’m writing this in response to Adam Machanic’s – T-SQL Tuesday - #001: Date/Time Tricks.
Here’s the a very useful script I still use all the time. I created it when I was working on a reporting project – it simply displays all the different date formats in SQL server.
--If you are looking to display dates, this script is a must!
---it prints out all the date formats and you can choose
SET NOCOUNT ON
Declare @TList table (
[TheDate] varchar(50) NOT NULL,
[Style] [int] NOT NULL)
--This will take care of 0 - 14
declare @counter int
set @counter = 0
while @counter < 15
begin
Insert @TList Select convert(varchar(50), Getdate(), @counter), @counter
set @counter = @counter + 1
end
--This will take care of 100 - 114
declare @counter2 int
set @counter2 = 100
while @counter2 < 115
begin
Insert @TList Select convert(varchar(50), Getdate(), @counter2), @counter2
set @counter2 = @counter2 + 1
end
Select * from @TList