Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to get the Month and Year from date

Posted on 2008-06-10
7
Medium Priority
?
5,299 Views
Last Modified: 2012-06-27
I want to extract MONTH-YEAR out of the date (datetime format)

Please advice how to do it...

Thanks in advance
0
Comment
Question by:redgreenred
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Expert Comment

by:powercram
ID: 21755122
In what context?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21755133
select mont(datefield), year(datefield)
from yourtable
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 100 total points
ID: 21755135
whoops...

select month(datefield), year(datefield)
from yourtable
0
 
LVL 18

Expert Comment

by:lludden
ID: 21756130
You can also use DATEPART to get any piece of a datetime value:

SELECT DATEPART(datepart,date)
where datepart is:

Datepart Abbreviations 
year     yy, yyyy 
quarter  qq, q 
month    mm, m 
dayofyear dy, y 
day      dd, d 
week     wk, ww 
weekday  dw 
hour     hh 
minute   mi, n 
second   ss, s 
millisecond ms 

Open in new window

0
 
LVL 3

Assisted Solution

by:cpleong99
cpleong99 earned 100 total points
ID: 21756483

select cast(month(datefield) as varchar(2)) + '-' + cast(year(datefield) as varchar(4))
from table1

this will return Month-Year
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question