Worth Corner, Crawley, RH10 7SL

Support Hours - Mon-Sat, 8.00-18.00

Welcome to our SQL Server blog

This blog was created in order to pass on some of our knowledge and advice in the hope that the community might find it useful.

Obviously Microsoft SQL Server is our area of expertise and therefore this is our most thorough blog with everything from the basic through to the the incredibly advanced and, as such, we should have something for everyone within our pages.

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.

SQL  World  CEO
Kevin  Urquhart

iPhone Selfie

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


© Copyright 2020 SQLTraining Ltd.