Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Finding a prior date by subtracting from today

Reply
Thread Tools

Finding a prior date by subtracting from today

 
 
Jim in Arizona
Guest
Posts: n/a
 
      12-27-2006
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
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      12-27-2006
"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)))"


 
Reply With Quote
 
 
 
 
Jim in Arizona
Guest
Posts: n/a
 
      12-27-2006
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
 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      12-27-2006
"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...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I know if a date is prior to today? Giampaolo Rodola' Python 4 03-25-2009 02:43 PM
Finding the value of "TOP" from prior block-containers used TadPole XML 2 11-12-2005 08:28 AM
Calculate the date after subtracting nmbr of days form a date Laery C Programming 11 02-25-2005 07:59 AM
subtracting days from date =?Utf-8?B?TWFubnkgQ2hvaGFu?= ASP .Net 5 11-09-2004 01:25 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57