Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get month name from date in Oracle

Tags:

date

sql

oracle

How to fetch month name from a given date in Oracle?

If the given date is '15-11-2010' then I want November from this date.

like image 667
Niraj Choubey Avatar asked Dec 21 '10 08:12

Niraj Choubey


People also ask

How do I get the month from a date in SQL?

To get a month from a date field in SQL Server, use the MONTH() function. This function takes only one argument – the date. This can be a date or date and time data type.

How can get month name from month number in SQL?

In SQL SERVER, we can use a combination of functions 'DATENAME' and 'DATEADD' functions to get a month name from a month number. Oracle: In Oracle, we can use a combination of functions 'TO_CHAR' and 'TO_DATE' functions to get a month name from a month number.

What is Trunc in Oracle?

The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt . The value returned is always of datatype DATE , even if you specify a different datetime datatype for date . If you omit fmt , then date is truncated to the nearest day.


2 Answers

select to_char(sysdate, 'Month') from dual 

in your example will be:

select to_char(to_date('15-11-2010', 'DD-MM-YYYY'), 'Month') from dual 
like image 149
Michael Pakhantsov Avatar answered Nov 02 '22 12:11

Michael Pakhantsov


Try this,

select to_char(sysdate,'dd') from dual; -> 08 (date) select to_char(sysdate,'mm') from dual; -> 02 (month in number) select to_char(sysdate,'yyyy') from dual; -> 2013 (Full year) 
like image 36
ASIK RAJA A Avatar answered Nov 02 '22 13:11

ASIK RAJA A