Click here to Skip to main content
13,295,051 members (68,154 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
André Kraak 7-Dec-12 9:20am
What is the data type of the date columns?
itsureshuk 7-Dec-12 9:22am
Rate this: bad
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.:)
itsureshuk 7-Dec-12 9:23am
mm format giving numeric month
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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]
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 |
Web02 | 2.8.171207.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2017
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