Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re[2]: How to calculate Last and First Day of Month?

Re[2]: How to calculate Last and First Day of Month?

From: <dgoulet_at_vicr.com>
Date: Thu, 24 Jan 2002 07:14:26 -0800
Message-ID: <F001.003F9B91.20020124054524@fatcity.com>

Hey Folks,

    The function last_day is there to handle all of that stuff, if you'll RTFM. Then using that and adding 1 day will always give you the first day of the next month without all of that substringing stuff.

    Sheesh, maybe we need a new 'obfuscated sql' contest again? Like who can come up with the most obscene way of calculating the 1st, or last, of the current month from sysdate.

Dick Goulet

PS: actually the answers could be very interesting.

____________________Reply Separator____________________
Author: Stephane Faroult <sfaroult_at_oriole.com>
Date:       1/23/2002 1:31 PM

Charlie Mengler wrote:
>
> I would have thought that the "first day of the month"
> is ALWAYS the 1st, as in 1 (ONE)!
>
> Please explain why it needs to be calculated or
> could be a value other than ONE.
>
> >
> > >>> stant_98_at_yahoo.com 01/23/02 10:35AM >>>
> > Hey guys,
> >
> > I know this is propablby easy, but I'm a bit
> > overwhelmed here this week. Can you please tell me how
> > to get first and last days of the month given SYSDATE?
> >
> > thanks a lot
> >
> > Regards
> >

Another case of 'On what day does Xmas fall this year? - on December 25th'.

I think that using the TRUNC() function with the suitable parameter must help you truncate SYSDATE to the first day of the month - perhaps TRUNC(SYSDATE, 'MM') or similar (too tired to RTFM). Then TO_CHAR with the suitable format should return whatever you want. For the last day, I presume that identifying the first day of the NEXT month and substracting 1 must simplify the 'is this 30/31/28/29' question.

-- 
Regards,

Stephane Faroult
Oriole Ltd
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Stephane Faroult
  INET: sfaroult_at_oriole.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: 
  INET: dgoulet_at_vicr.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Thu Jan 24 2002 - 09:14:26 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US