Solved

how to get the Month and Year from date

Posted on 2008-06-10
7
5,293 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 6

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 25 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 25 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

730 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