Date Formatting Examples in SQL Server

There are various ways to display and store dates in SQL Server. You can easily use the FORMAT function get the date value into a format most useful for your query results, but with great flexibility often comes confusion. It is helpful to see a few simple examples. In this article from Greg Owen, we see several examples of ways to display the current date and time.

–Get Current Date and Time

select getdate()

–Date Format MMM DD YYYY

select convert(nvarchar(12),getdate(),100)

–Date Format MM/DD/YYYY

select convert(nvarchar(10),getdate(),101)

–Date Format YYYY.MM.DD

select convert(nvarchar(10),getdate(),102)

–Date Format DD/MM/YYYY

select convert(nvarchar(10),getdate(),103)

–Date Format DD.MM.YYYY

select convert(nvarchar(10),getdate(),104)

–Date Format DD-MM-YYYY

select convert(nvarchar(10),getdate(),105)

–Date Format DD MMM YYYY

select convert(nvarchar(11),getdate(),106)

–Date Format MMM DD, YYYY

select convert(nvarchar(12),getdate(),107)

–Date Format hh:mm:ss (24hr)

select convert(nvarchar(10),getdate(),108)

–Date Format hh:mm:ss:mmm (AM PM)

select convert(nvarchar(30),getdate(),109)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s