Categories
Sql Server

Date and Time Conversions Using SQL Server

Date and Time Conversions Using SQL Server

Hi guys, in this tutorial i will let you know Date and Time Conversions Using SQL Server.Microsoft SQL Server provides various options to format a date/time string.The most common is the current date/time using getdate().It provides the current date and time according the server providing the date and time. If a universal date/time is needed, then getutcdate()should be used.

DATE FORMATS
Format Query (current date: 04/30/2012) Results
1 select convert(varchar, getdate(), 1) 04/30/12
2 select convert(varchar, getdate(), 2) 12.04.30
3 select convert(varchar, getdate(), 3) 30/04/12
4 select convert(varchar, getdate(), 4) 30.04.12
5 select convert(varchar, getdate(), 5) 30-04-12
6 select convert(varchar, getdate(), 6) 30 Apr 12
7 select convert(varchar, getdate(), 7) Apr 30, 12
10 select convert(varchar, getdate(), 10) 04-30-12
11 select convert(varchar, getdate(), 11) 12/04/30
101 select convert(varchar, getdate(), 101) 04/30/2012
102 select convert(varchar, getdate(), 102) 2012.04.30
103 select convert(varchar, getdate(), 103) 30/04/2012
104 select convert(varchar, getdate(), 104) 30.04.2012
105 select convert(varchar, getdate(), 105) 30-04-2012
106 select convert(varchar, getdate(), 106) 30 Apr 2012
107 select convert(varchar, getdate(), 107) Apr 30, 2012
110 select convert(varchar, getdate(), 110) 04-30-2012
111 select convert(varchar, getdate(), 111) 2012/04/30