Popular Date Time formats in SQL Server

We usually come across scenario's where different date time conversions and formats are required in our day to day development activities.

here are some useful format codes used in SQL Server -


select convert(varchar(20),GETDATE(),100) --Apr 6 2011 4:38AM
select convert(varchar(20),GETDATE(),101) --04/06/2011            (MM/DD/YYYY)
select convert(varchar(20),GETDATE(),102) --2011.04.06            (YYYY.MM.DD)
select convert(varchar(20),GETDATE(),103) --06/04/2011            (DD/MM/YYYY)
select convert(varchar(20),GETDATE(),104) --06.04.2011            (DD.MM.YYYY)
select convert(varchar(20),GETDATE(),105) --06-04-2011            (DD-MM-YYYY)
select convert(varchar(20),GETDATE(),106) --06 Apr 2011
select convert(varchar(20),GETDATE(),107) --Apr 06, 2011
select convert(varchar(20),GETDATE(),108) --04:42:19              (HH:MM:SS)
select convert(varchar(20),GETDATE(),109) --Apr 6 2011 4:42:47
select convert(varchar(20),GETDATE(),110) --04-06-2011            (MM-DD-YYYY)
select convert(varchar(20),GETDATE(),111) --2011/04/06            (YYYY/MM/DD)
select convert(varchar(20),GETDATE(),112) --20110406              (YYYYMMDD)
select convert(varchar(20),GETDATE(),113) --06 Apr 2011 04:44:10
select convert(varchar(20),GETDATE(),114) --04:44:25:583          (HH:MM:SS:sss)
select convert(varchar(20),GETDATE(),120) --2011-04-06 04:45:20

Comments

Popular posts from this blog

Deleting Duplicate Data From SQL Server Table

SSIS vs. T-SQL

Excel Based Reporting