Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format 1

Status
Not open for further replies.

kermitforney

Technical User
Mar 15, 2005
374
US
Trying to take a DATETIME data type and CAST/CONVERT it to just display as month day or mm/dd 04/04 and leave off the year.

Have not been able to find this anywhere.

Thanks in Advance.
 
You can convert to varchar. The convert function has a 3rd argument allowing you to specify the style. Style 101 is mm/dd/yyyy. The first 5 characters match your desired output, so....

Code:
Select Convert(VarChar([!]5[/!]), YourColumnNameHere, 101)

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Tested and works great!

Code:
Select CONVERT(VARCHAR(5), GETDATE(), 101)
Thanks again GM!!
 
You're welcome.

month day
You may also want to try this:

Code:
Select Convert(VarChar(6), GetDate(), 100)

It will give you the month abbreviation and the day. If the day is a single digit (like March 4th), there will be 2 spaces between the month abbreviation and the day.

Mar<space><space>4
Mar<Space>10

All months are abbreviated to 3 characters.

If you don't like the abbreviation, then...

Code:
Select dateName(Month, GetDate()) + ' ' + Convert(VarChar(2), Day(GetDate()))


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top