Site Loader
Get a Quote

In this tutorial, I am going to tell you how to Format DateTime  in SQL Server

Format DateTime in SQL SERVER

Format DateTime and Date SQL SERVER:- Common Requirement for any developer nowadays is to format Date and DateTime in SQL Server.Below are some scripts to get the required format.

Format DateTime

You must follow the following links.

User Defined Function to Extract Number From String in SQL Server.

Generate Random Number in SQL Server

1)  Format- mon dd yyyy hh:mmAM (or PM)

Query to Format date and DateTime in SQL Server –  SELECT convert(varchar, getdate(), 100)

OUTPUT  — Jun 28, 2016, 3:39PM

2) Format- mm/dd/yyyy

Query to Format date and datetime in Sql Server SELECT convert(varchar, getdate(), 101)

Output- 06/28/2016

3) Format-  yyyy.mm.dd

Query to Format date and datetime in Sql Server- SELECT convert(varchar, getdate(), 102)

Output- 2016.06.28

4) Format-  dd/mm/yyyy

Query to Format date and datetime in Sql Server- SELECT convert(varchar, getdate(), 103)

Output- 28/06/2016

5) Format- dd.mm.yyyy

Query- SELECT convert(varchar, getdate(), 104)

Output- 28.06.2016

6) Format- dd-mm-yyyy

Query- SELECT convert(varchar, getdate(), 105)

Output- 28-06-2016

7) Format- dd mon yyyy

Query- SELECT convert(varchar, getdate(), 106)

Output- 28 Jun 2016

8) Format- mon dd, yyyy

Query- SELECT convert(varchar, getdate(), 107)

Output- Jun 28, 2016

9) Format- mon dd yyyy hh:mm:ss:mmmAM (or PM)

Query- SELECT convert(varchar, getdate(), 109)

Output- Jun 28 2016  3:53:32:580PM

10) Format- mm-dd-yyyy

Query- SELECT convert(varchar, getdate(), 110)

Output- 06-28-2016

11) Format- yyyy/mm/dd

Query- SELECT convert(varchar, getdate(), 111)

Output- 2016/06/28

12) Format- yyyymmdd

Query- SELECT convert(varchar, getdate(), 112)

Output- 20160628

13) Format- dd mon yyyy hh:mm:ss:mmm

Query- SELECT convert(varchar, getdate(), 113)

Output- 28 Jun 2016 15:57:25:063

14) Format- hh:mm:ss:mmm(24h)

Query- SELECT convert(varchar, getdate(), 114)

Output- 15:58:19:950

15) Format- hh:mm:ss:mmm(24h)

Query- SELECT convert(varchar, getdate(), 120)

Output- 2016-06-28 15:59:52

16) Format- yyyy-mm-dd hh:mm:ss.mmm

Query- SELECT convert(varchar, getdate(), 121)

Output- 2016-06-28 16:00:40.233

17) Format- yyyy-mm-ddThh:mm:ss.mmm

Query- SELECT convert(varchar, getdate(), 126)

Output- 2016-06-28T16:01:29.687

Conclusion :-

I hope you would like this post about Format DateTime and Date SQL SERVER.Please give feedback if you want to see improvement.Your Feedback matters to us.

Post Author: TechieFlair

Leave a Reply

Your email address will not be published.