Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: ??? Number of days betwwen two dates?
Cecil wrote:
>
> Huang,
>
> If you buy Steven Feuersteins Book on PL/SQL programming which
>
> you must, you will get all these problems sorted out with a disk of
> scripts.
>
> Cecil
>
> Huang, Joseph wrote in article <5rnq02$d28_at_bolivia.earthlink.net>...
>
> I need a function, which I can use in other stored procedures, to
> return number of days of two given dates. The only similar function I
> can found in Oracle manual is MONTHS_BETWEEN(). However, the problem
> is MONTHs_BETWEEN() return number based on 31-day month which is
> incorrect normally. For example, instead of 29 days, the function
> returns 1.0322581 (32 days) from 02/01/97 to 03/02/97.
>
> Before writing our own function to get correct number of days, I'd
> like to know whether this kind of function exists somewhere so I don't
> need to redo it. Any suggestions?
>
> Thanks in advance.
>
> Joseph Huang
>
> --
> My email address is intentionally invalid to foil spammers. Delete
> the ".---" to get my real address.
>
> Name: Daternge.sf
> Part 1.2 Type: unspecified type (application/octet-stream)
> Encoding: 7bit
For goodness' sake!
Why buy a book when the answer is simply that the result of subtracting
two date columns is *defined* as being the difference in days between
the two dates!
Note that "date_column_1 - date_column_2" may give unexpected results if either of the column values contains a time component, If this is likely to be a problem, use "trunc(date_column_1) - trunc(date_column_2)"
HTH.
-- Chrysalis FABRICATI DIEM, PVNC ('To Protect and to Serve') Terry Pratchett : "Guards Guards"Received on Wed Jul 30 1997 - 00:00:00 CDT