Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format Date in SQL Server Query

Posted on 2016-10-04
5
Medium Priority
?
81 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 2000 total points
ID: 41827903
Or relying on truncation:

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

Open in new window

0
 
LVL 30

Expert Comment

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

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

Open in new window

0
 
LVL 52

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

715 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