Sometime it is needed to show dates in different format to end user.
We can set date format in SQL Query as well as in ASP.NET code(C# & Vb.Net).
If we are working with SQL server, then we can set date format in SQL server
queries.
SQL server support different methods to show dates. I have explained these formats.
SELECT CONVERT(VARCHAR,GETDATE(),100) --Output: Feb 18 2011 10:39PM
SELECT CONVERT(VARCHAR,GETDATE(),101) --Output: 02/18/2011
SELECT CONVERT(VARCHAR,GETDATE(),102) --Output: 2011.02.18
SELECT CONVERT(VARCHAR,GETDATE(),103) --Output: 18/02/2011
SELECT CONVERT(VARCHAR,GETDATE(),104) --Output: 18.02.2011
SELECT CONVERT(VARCHAR,GETDATE(),105) --Output: 18-02-2011
SELECT CONVERT(VARCHAR,GETDATE(),106) --Output: 18 Feb 2011
SELECT CONVERT(VARCHAR,GETDATE(),107) --Output: Feb 18, 2011
SELECT CONVERT(VARCHAR,GETDATE(),108) --Output: 22:40:38
SELECT CONVERT(VARCHAR,GETDATE(),109) --Output: Feb 18 2011 10:40:42:500PM
SELECT CONVERT(VARCHAR,GETDATE(),110) --Output: 02-18-2011
SELECT CONVERT(VARCHAR,GETDATE(),111) --Output: 2011/02/18
SELECT CONVERT(VARCHAR,GETDATE(),112) --Output: 20110218
SELECT CONVERT(VARCHAR,GETDATE(),113) --Output: 18 Feb 2011 22:41:02:327
SELECT CONVERT(VARCHAR,GETDATE(),114) --Output: 22:41:07:640
SELECT CONVERT(VARCHAR,GETutcDATE(),114) --Output: 15:41:34:170
0 comments:
Post a Comment