Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    8

    Unanswered: Help with Date function in stored proc

    Hi,

    Im automating a report that will run M-F. I need to write date functionality using getdate() in the stored procedure that will calculate and retrieve records for one day prior for the Tues, Wed, Thurs, Friday runs. The Monday run will need to calculate and retrieve records for Fri, Sat, & Sun.

    Can anyone help with this or provide examples using dateadd or similar?
    Thanks,
    Colin

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Code:
    select whatever
    from yourtable
    where thedate 
      between 
        dateadd(dd,
          case when datepart(dw,getdate())=2 then -3 
          else -1 
        end,dateadd(dd,datediff(dd,'19000101',getdate()),'19000101'))
      and dateadd(ms,-3,dateadd(dd,datediff(dd,'19000101',getdate()),'19000101'))

Posting Permissions

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