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.
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.
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.
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.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With