473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Finding a prior date by subtracting from today

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
Dec 27 '06 #1
3 2323
"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:uU****************@TK2MSFTNGP04.phx.gbl...
"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)))"
Dec 27 '06 #2
Mark Rae wrote:
"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:uU****************@TK2MSFTNGP04.phx.gbl...
>"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
Dec 27 '06 #3
"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:O9**************@TK2MSFTNGP04.phx.gbl...
>"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...
Dec 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: adam | last post by:
Hi all, I am having a problem with calculating a date. What I am looking to do is get the date of Sunday of this week, then use mktime() to find out other days in the past by subtracting days. ...
20
by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
3
by: Brynn | last post by:
Here is a function where you don't have to worry about the leap year. You will have to still be aware of time differences between you and the server, and correct your data before entering it into...
2
by: User 2084 | last post by:
Hello all. I'm an access newbie trying to learn how to do basic database data manipulations. I had a hard time searching the archives on this question as I don't really know what I'm looking for in...
1
by: Budd | last post by:
Hi everyone i got a problem on date, it is... 1, i get the date from calendar component 2, compare today and selected date is equal (compare method) 3 count the number of day between this...
5
by: dan | last post by:
I could find no documentation that the Date object has useful wrapping properties. For example, write(new Date(2007, 11 + 1, 1)) results in January 1st 2008. And write(new Date(2007, 0, 31 + 1))...
3
by: shmoopie | last post by:
Hi, I have a php form that I want to use to pass a user specified "start date" and "end date" to a mysql database to retrieve reservations. I want the number of days up to and including the "end...
3
by: Tony B | last post by:
I'm trying to write a simple vb function that takes a current date and calculates for the first day of the month of that date what day of the week it is. I thought I could take a date object dt,...
11
by: soni2926 | last post by:
Hi, I have a function where i need to check the date passed in is within 90days of today. Could someone help me get this to work, how do i do the 90 days compare with today? <script...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.