Home » SQL & PL/SQL » SQL & PL/SQL » how to find number of days in a given month. (SQL PLUS ORACLE 10G)
how to find number of days in a given month. [message #607469] Fri, 07 February 2014 00:56 Go to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

i want to find number of days in a given month, that means if if provide value 'march' then it should display 31 days ,if 'february' then 28or29 days .
Please tell how to do that.
Re: how to find number of days in a given month. [message #607470 is a reply to message #607469] Fri, 07 February 2014 00:57 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Now when you want 28 or 29, I will say manually do it, use case statement.

Manu
Re: how to find number of days in a given month. [message #607471 is a reply to message #607470] Fri, 07 February 2014 01:06 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

NO THATS NOT MY REQUIREMENT , MY REQUIREMENT IS LIKE THIS:-
SELECT NO_OF_DAYS FROM DUAL
WHERE TO_CHAR(SYSDATE,'MONTH')='MONTH_NAME';
Re: how to find number of days in a given month. [message #607472 is a reply to message #607471] Fri, 07 February 2014 01:15 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

You are expecting something like this:

SQL> select to_char(add_months(trunc(sysdate,'month'),1)-1,'dd') last_date from dual;

LA
--
28


Manu
Re: how to find number of days in a given month. [message #607474 is a reply to message #607472] Fri, 07 February 2014 01:26 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
you could use last_day function also, here an example that works for the "current year" (february differs bec. of leap year):
SELECT TO_CHAR(LAST_DAY(TO_DATE('february', 'month')),'dd') FROM dual;

28                                                                         
1 row selected.


SELECT TO_CHAR(LAST_DAY(TO_DATE('march', 'month')),'dd') FROM dual;

31                                                                         
1 row selected.


With year:
SELECT TO_CHAR(LAST_DAY(TO_DATE('2016/february', 'yyyy/month')),'dd') FROM dual;

29                                                      
1 row selected.

[Updated on: Fri, 07 February 2014 01:31]

Report message to a moderator

Re: how to find number of days in a given month. [message #607475 is a reply to message #607474] Fri, 07 February 2014 01:34 Go to previous message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

LOL SO EASY ,THANKS BUDDY Smile
Previous Topic: user creation
Next Topic: parse blob into rows
Goto Forum:
  


Current Time: Thu Apr 25 18:49:22 CDT 2024