Click here to Skip to main content
12,292,953 members (65,733 online)
Rate this:
 
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 26-Sep-12 11:36am
   
5ed. Its always a great fun to work with DATEPART, DATENAME and other Sql Server functions.!
Maciej Los 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 26-Sep-12 11:30am
   
+5. I didn't see the oracle tag.
RaisKazi 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160518.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2016
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