Date and Time Formats in SQL Server
Published: Oct 14, 2013
There are numerous times you might want your dates returned in a different format and SQL Server will cater for this.

Running the following script will show the different date and time formats you have available…

declare @conversion tinyint = 101,
        @datetime datetime = current_timestamp

declare @dateFormat table
    formatCode varchar(40),
    result varchar(25)

while @conversion <= 150
    begin try
        insert into @dateFormat
        select 'CONVERT(varchar, current_timestamp, ' +
                CONVERT(varchar, @conversion) + ')',
                CONVERT(varchar, @datetime, @conversion)
    end try
    begin catch
    end catch

    set @conversion += 1

select *
from @dateFormat
Leave a Comment
Your email address will not be published. All fields are mandatory.
NB: Comments will only appear once they have been moderated.

Your SQL Trainer
Kevin Urquhart

I am a SQL Server DBA, Architect, Developer, and Trainer for SQL Training. This is my blog in which I’m simply trying to share my SQL knowledge and experiences with the world.

Kevin Urquhart
SQL Server Consultant, London



Copyright © 2018 London SQL Server Training Courses @ SQL Training | Website Design From Scott Heron