Finding a prior date by subtracting from today

Discussion in 'ASP .Net' started by Jim in Arizona, Dec 27, 2006.

  1. I'm having difficulty figuring out how to find the date three days from
    today's date.

    I'm trying to use an sql select statement, like so:

    "SELECT * FROM TableA " & _
    "WHERE DateColumn BETWEEN " & _
    BeginDate & " AND " & EndDate

    I want to display records that are from three days ago to the present.

    I don't know how to find the date from three days ago. Something like:

    Dim EndDate as Date = Now() 'Or DateAndTime.Today
    Dim BeginDate as Date = DateAndTime.Today - 3

    Of course, that doesn't work.

    Any Ideas?

    TIA,
    Jim
     
    Jim in Arizona, Dec 27, 2006
    #1
    1. Advertising

  2. Jim in Arizona

    Mark Rae Guest

    "Jim in Arizona" <> wrote in message
    news:uUaWy%...

    > "SELECT * FROM TableA " & _
    > "WHERE DateColumn BETWEEN " & _
    > BeginDate & " AND " & EndDate
    >
    > I want to display records that are from three days ago to the present.


    "SELECT * FROM TableA " & _
    "WHERE DateColumn <= " & _
    "DATEADD(d, -3, CONVERT(datetime, CONVERT(varchar, getdate(), 106)))"
     
    Mark Rae, Dec 27, 2006
    #2
    1. Advertising

  3. Mark Rae wrote:
    > "Jim in Arizona" <> wrote in message
    > news:uUaWy%...
    >
    >> "SELECT * FROM TableA " & _
    >> "WHERE DateColumn BETWEEN " & _
    >> BeginDate & " AND " & EndDate
    >>
    >> I want to display records that are from three days ago to the present.

    >
    > "SELECT * FROM TableA " & _
    > "WHERE DateColumn <= " & _
    > "DATEADD(d, -3, CONVERT(datetime, CONVERT(varchar, getdate(), 106)))"
    >
    >


    I actually glanced at the DateAdd function on a webpage somewhere and
    within Microsoft.VisualBasic.DateAndTime but wasn't sure about its use.

    So, this works just as good on the vb code side:

    Dim BeginDate As Date = DateAdd(DateInterval.Day, -3, DateAndTime.Today)

    So, which would be more effective, do you think? Using DateAdd in the vb
    code or in the SQL? I plan on using an SQL Stored Proc for the SQL
    instead of storing it in a string on the vb code side.

    Thanks Mark.

    Jim
     
    Jim in Arizona, Dec 27, 2006
    #3
  4. Jim in Arizona

    Mark Rae Guest

    "Jim in Arizona" <> wrote in message
    news:...

    >> "SELECT * FROM TableA " & _
    >> "WHERE DateColumn <= " & _
    >> "DATEADD(d, -3, CONVERT(datetime, CONVERT(varchar, getdate(), 106)))"


    > So, this works just as good on the vb code side:
    >
    > Dim BeginDate As Date = DateAdd(DateInterval.Day, -3, DateAndTime.Today)


    Yep.

    > So, which would be more effective, do you think? Using DateAdd in the vb
    > code or in the SQL? I plan on using an SQL Stored Proc for the SQL instead
    > of storing it in a string on the vb code side.


    I don't suppose it matters *too* much in the general scheme of things -
    however, I tend to use a stored procedure whenever I can because of its
    precompiled execution plan...
     
    Mark Rae, Dec 27, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFubnkgQ2hvaGFu?=

    subtracting days from date

    =?Utf-8?B?TWFubnkgQ2hvaGFu?=, Nov 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    27,490
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Nov 9, 2004
  2. TB
    Replies:
    0
    Views:
    453
  3. TadPole
    Replies:
    2
    Views:
    510
    TadPole
    Nov 12, 2005
  4. Laery
    Replies:
    11
    Views:
    983
    Laery
    Feb 25, 2005
  5. Giampaolo Rodola'

    How can I know if a date is prior to today?

    Giampaolo Rodola', Mar 25, 2009, in forum: Python
    Replies:
    4
    Views:
    298
    John Machin
    Mar 25, 2009
Loading...

Share This Page