Click here to Skip to main content
12,634,101 members (26,668 online)
Rate this:
 
Please Sign up or sign in to vote.
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 7-Dec-12 4:13am
Comments
André Kraak 7-Dec-12 9:20am
   
What is the data type of the date columns?
itsureshuk 7-Dec-12 9:22am
   
datetime
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Hope this helps.:)
  Permalink  
Comments
itsureshuk 7-Dec-12 9:23am
   
mm format giving numeric month
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try
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]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100