Re: 2 month rolling average/sql*plus

From: David M. Sloan <dsloan_at_us.oracle.com>
Date: 1995/08/09
Message-ID: <40aoon$ffm_at_inet-nntp-gw-1.us.oracle.com>#1/1


Fernando Luna <fern_at_aa.net> wrote:
>Hi Jenny!
>On 8 Aug 1995, Jenny Farnham wrote:
>> How would one do the "date math" for this?
>A quick and dirty way of doing this is
> select to_char(sysdate, 'MON') from dual; (For the current month)
> select to_char(sysdate -30, 'MON') from dual; (Last Month)
> select to_char(sysdate -60, 'MON') from dual; (Month before that)
It may be quick, but it's very dirty. Don't try running it on the last day of a 31 day month or the first of March. You'll be very disappointed. ;-)

Consider the following function to help you out...  trunc (date_column, 'MONTH')
chops off days and just looks at the month you're in.

>=========================================================
>Fernando Luna E-mail: fern_at_aa.net
>Kent, WA HomePage: http://www.aa.net/~fern/
>
>=========================================================

  • Dave Sloan dsloan_at_us.oracle.com
Received on Wed Aug 09 1995 - 00:00:00 CEST

Original text of this message