Solved

Format Date in SQL Server Query

Posted on 2016-10-04
5
30 Views
Last Modified: 2016-10-04
I'm sure this is simple but I can't seem to figure it out. I need to format my date field to just mm/dd. How can I do this in my SQL Query?
0
Comment
Question by:Lawrence Salvucci
5 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41827900
You could just use:

select right('0' + cast(month(getdate()) as nvarchar(2)), 2) + '/' + right('0' + cast(day(getdate()) as nvarchar(2)), 2)

Open in new window

0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 41827903
Or relying on truncation:

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

Open in new window

0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41827904
Please try below. Really easy..

SELECT FORMAT ( GETDATE() , 'MM/dd' ) [MonthDay]

Open in new window

0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 41827906
FORMAT function is available since SQL Server 2012. If you're using 2012 version or superior then you can use SELECT FORMAT( @d, 'MM/dd', 'en-US' )
0
 
LVL 1

Author Closing Comment

by:Lawrence Salvucci
ID: 41827909
Thank you very much for your quick response. This was the easiest solution and worked exactly how I wanted it to. Thank you again.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Counts 11 40
SQL Server RDS clr assembly 4 35
Managing SQL log files, SQL Server 2014 6 55
Recurring Excel Timelime for Veeam 2 31
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now