Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Oracle
In my table i have one field which contains the date, i want to take only month from that
is it possible?
similarly how can i take month from system date?
Posted 26-Sep-12 5:19am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use the DATEPART function to get the month number or DATENAME function to get the month name.
select datepart(month,Mydate), datename(month,Mydate)
Source[^]
 
See Solution 2 for the oracle answer. (I didn't see that tag, sorry)
  Permalink  
v2
Comments
RaisKazi at 26-Sep-12 11:36am
   
5ed. Its always a great fun to work with DATEPART, DATENAME and other Sql Server functions.!
Maciej Los at 26-Sep-12 15:55pm
   
Good work! +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

For SQL Server
SELECT MONTH(MyDateColunm) from MyTable;
 
To get System/Current Month.
SELECT MONTH(GETDATE());
 
For Oracle
select to_char(MyDateColunm, 'Month') from MyTable;
To get System/Current Month.
select to_char(sysdate, 'Month') from dual;
  Permalink  
Comments
Marcus Kramer at 26-Sep-12 11:30am
   
+5. I didn't see the oracle tag.
RaisKazi at 26-Sep-12 11:35am
   
Thank you Marcus!.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
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