What are the different types of Date formats in SQL Server?
GETDATE
The GETDATE function returns the current system date and time. The syntax is as follows:
GETDATE()
Example:
Select GETDATE() as CurrentDate
Output:
2013-06-23 21:55:40.113
Now i'll explain how to get different date formats.
Different Date format examples:
Select Datename(day,getdate())+'-'+substring(Datename(month,getdate()),1,3)+'-'+Datename(year,getdate())
Output:
24-Jun-2013
Select CONVERT(varchar, getdate(), 101) as [Date Format]
Output:
06/23/2013
Select CONVERT(varchar, getdate(), 102) as [Date Format]
Output:
2013.06.23
Select CONVERT(varchar, getdate(), 103) as [Date Format]
Output:
23/06/2013
Select CONVERT(varchar, getdate(), 104) as [Date Format]
Output:
23.06.2013
Select CONVERT(varchar, getdate(), 105) as [Date Format]
Output:
23-06-2013
Select CONVERT(varchar, getdate(), 106) as [Date Format]
Output:
23 Jun 2013
Select CONVERT(varchar, getdate(), 107) as [Date Format]
Output:
Jun 23, 2013
Select CONVERT(varchar, getdate(), 108) as [Date Format]
Output:
21:40:18
Select CONVERT(varchar, getdate(), 109) as [Date Format]
Output:
Jun 23 2013 9:40:18:200PM
Select CONVERT(varchar, getdate(), 110) as [Date Format]
Output:
06-23-2013
Select CONVERT(varchar, getdate(), 111) as [Date Format]
Output:
2013/06/23
Select CONVERT(varchar, getdate(), 112) as [Date Format]
Output:
20130623
Select CONVERT(varchar, getdate(), 113) as [Date Format]
Output:
23 Jun 2013 21:40:18:200
Select CONVERT(varchar, getdate(), 114) as [Date Format]
Output:
21:40:18:200
-
CreatedJun 23, 2013
-
UpdatedNov 03, 2020
-
Views3,503
Related Articles
Different types of variables in SQL Server
What is Cross Join in SQL Server
How delete record from parent table when there is Foreign Key relation in SQL Server
What is the differences between CHAR, NCHAR, VARCHAR and NVARCHAR in SQL Server?
How to use Delete Command in SQL Server?
How to add or remove a column from a table in SQL Server?
How to insert values into Identity Column in SQL Server?
How to get a fixed-length value in SQL Server?
What is Left Join (or) Left Outer Join in SQL Server?
How to get current week dates in SQL Server?