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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing mm/yyyy from a date field 1

Status
Not open for further replies.
Mar 20, 2009
102
US
How can I get the date field to only print the mm/yyyy as opposed to the entire date?

Thanks!
 
This is what I have and it is giving me this error:

Incorrect syntax near the keyword 'Convert'.

Convert(VarChar(2),Month(getdate()))+'/'+Convert(VarChar(4), year(getdate()))
 
First idea that comes to mind is

select cast(month(dtField) as char(2)) + '/' + cast(year(dtField) as char(4)) as MonthYear
 
there's probably 100 different ways. I preference is...

Code:
Select Right(Convert(VarChar(10), GetDate(), 103), 7)


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks gmmastros. Your post helped me tremendously. I couldn't remember this syntax. I used Right(Convert(VarChar(15), GETDATE(), 106), 8) to return the following format:

JUN 2009

BTW, you get a star.

Thanks in advance,
Donald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top