DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Last_day & Next_day

  1. #1
    Join Date
    Mar 2004
    Posts
    55

    Last_day & Next_day

    Why does the top one work yet the bottom one doesen't?

    SELECT LAST_DAY(TO_DATE(Add_months(SYSDATE, -1))) FROM dual

    SELECT NEXT_DAY(TO_DATE(Add_months(SYSDATE, -3))) FROM dual


    basically i want to be able to find the first date of a given month given the current date.

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    You need to check the manuals to see how NEXT_DAY function works - it doesn't work like you currently think it does!

    As for getting the first day of the month for a given date, one (of the many) method is:

    SELECT TRUNC(:date,'MM') FROM dual;
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Also, the TO_DATE() function is redundant in your code.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width