Re: Oracle Dates

From: Malcolm Dew-Jones <yf110_at_vtn1.victoria.tc.ca>
Date: 6 Jan 2010 13:48:59 -0700
Message-ID: <4b45054b$1_at_news.victoria.tc.ca>



The Magnet (art_at_unsu.com) wrote:
: On Jan 5, 6:48=A0pm, yf..._at_vtn1.victoria.tc.ca (Malcolm Dew-Jones)
: wrote:
: > The Magnet (a..._at_unsu.com) wrote:
: >
: > : Is there a way for me to figure out how many days in 3 months? =A0For
: >
: > I can't test this, but my first thought is to try something like this
: > example for counting the days in Jan Feb and March of this year.
: >
: > =A0 =A0 =A0 =A0 number count_days_in_3_months :=3D
: > =A0 =A0 =A0 =A0 to_date('1-APR-2010','DD-MON-YYYY')
: > =A0 =A0 =A0 =A0 - to_date('1-JAN-2010','DD-MON-YYYY')

: Yes, but I do not actually know the months. All I know is that the
: offset starts with "v_date", and I want to count the days, 3 months
: forward. Hoping not to have to code a bunch of stuff, must be some
: function or something.

(All code untested).

I assume you know the start month, or how else can you do this at all? SYSDATE and other things can give you the current year and/or month, perhaps using to_char or trunc to get the parts you need in the format you need.

So to get the last month (in my example four months from the start month), where the start month is the current month you could do something like this. (untested, in particular I think that trunc to MON month gives a date that is the first of the month of the year).

        DATE start_of_first_month := trunc( sysdate , 'MON');

	DATE arbitrary_day_in_month_4 :=
	add_months( start_of_first_month , 4);

	-- probably redundant
	DATE first_day_of_month_four :=
	trunc( arbitrary_day_in_month_4 , 'MON');

	NUMBER count_of_days := 
	first_day_of_month_four - start_of_first_month;
Received on Wed Jan 06 2010 - 14:48:59 CST

Original text of this message