Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi frnds,
I have two date column. in that i have to take month and year and combine as follows.
Date1 Date2
01-03-2012 01-05-2013

I need Output as : Mar-2012 - May-2013
Posted
Comments
André Kraak 7-Dec-12 9:20am    
What is the data type of the date columns?
itsureshuk 7-Dec-12 9:22am    
datetime

To get Month of the given date:select datename(mm,getdate())
To get Year of given date: select DATENAME(yyyy,GETDATE())

Hope this helps.:)
 
Share this answer
 
Comments
itsureshuk 7-Dec-12 9:23am    
mm format giving numeric month
Try
SQL
SELECT LEFT(DATENAME(mm,Date1),3) + '-' + CAST(DATEPART(YEAR,Date1) AS VARCHAR) + ' - ' + LEFT(DATENAME(mm,Date2),3) + '-' + CAST(DATEPART(YEAR,Date2) AS VARCHAR),* FROM [YourTable]
 
Share this answer
 
Comments
itsureshuk 7-Dec-12 9:36am    
thank u,working fine
__TR__ 7-Dec-12 9:37am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900