Solved

how to get the Month and Year from date

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

765 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