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

Thread: pulling data from current date back to 1st of the month

  1. #1
    Join Date
    Jan 2002
    Posts
    18

    Question

    hi,

    i want to automate a query that pulls data from the current date back through the first of the month. i want it to run every day.

    something like:

    select colname from table where createdate >= {first_of_the_month} and createdate <= sysdate;

    how can automate first_of_the_month without additional processing? i see a way i could do it from now til end of month with last_day(), but nothing like first_day.

    thanks!

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    last day of the month prior plus one day?

  3. #3
    Join Date
    Jan 2002
    Posts
    18
    oh, you mean something like

    last_day(add_months(sysdate, -1)) + 1

    will add_months(sysdate, -1) always give me the prior month ?

  4. #4
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Yup
    Jeff Hunter

  5. #5
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Instead of using two functions (LAST_DAY + ADD_MONTHS) you can simply get it by using TRUNC function:

    TRUNC(sysdate,'MM')
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

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