Different Date Formats

,

This is handy script to print all available date formats in SQL Server.

We dont always remember the style we need, in time and this script helps us identify which one we need.

CONVERT() function is short and the same info returned by this function, can be printed using DatePart ()and CAST() functions too. We end up writing lengthy functions then.

 

DECLARE @style_no_century tinyint, @style_century tinyint

SET @style_no_century = 0
SET @style_century = 100

WHILE @style_no_century <= 14 
BEGIN
 PRINT CONVERT (varchar, @style_no_century) + ' - ' + CONVERT(varchar, getdate(), @style_no_century)
 PRINT '----------------------------------'
 SET @style_no_century = @style_no_century + 1
END

WHILE @style_century <= 114
BEGIN
 PRINT CONVERT (varchar, @style_century) + ' - ' + CONVERT(varchar, getdate(), @style_century)
 PRINT '----------------------------------'
 SET @style_century = @style_century + 1
END

Rate

4.2 (10)

Share

Share

Rate

4.2 (10)