Solved

Format Date in SQL Server Query

Posted on 2016-10-04
5
58 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 28

Expert Comment

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

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

Open in new window

0
 
LVL 50

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

751 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