Avatar of Lawrence Salvucci
Lawrence Salvucci
Flag for United States of America asked on

Format Date in SQL Server Query

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?
Microsoft SQL Server

Avatar of undefined
Last Comment
Lawrence Salvucci

8/22/2022 - Mon
Lee

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

ASKER CERTIFIED SOLUTION
Lee

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pawan Kumar

Please try below. Really easy..

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

Open in new window

Vitor Montalvão

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' )
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Lawrence Salvucci

ASKER
Thank you very much for your quick response. This was the easiest solution and worked exactly how I wanted it to. Thank you again.