|
-
Apr 11th, 2005, 05:17 AM
#1
Thread Starter
Hyperactive Member
comparing dates resolved
i have a table that contains dates and rates, i want to create a query which returns the rate corresponding to todays date or the closest date in the past
(i know how to say select where date = a certain date but how do i do the above???)
any ideas????
Last edited by pame1la; Apr 11th, 2005 at 06:54 AM.
-
Apr 11th, 2005, 05:28 AM
#2
Hyperactive Member
Re: comparing dates
loop through the date values and then compare them to today's date using
ChosenDate = ?
TodaysDate = Date
Days = datediff("d",TodaysDate,ChosenDate)
then the the Days variable will tell you how many days there are between the dates (0 would be today) so in your app you could find the date with the lowest days value and use that
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Apr 11th, 2005, 05:35 AM
#3
Thread Starter
Hyperactive Member
Re: comparing dates
okay so i am right in thinkin i would have a sql query which will call all the dates and rates from the table, then compare dates with todays date storing the difference in an array. Then go through the array, and find the smallest diff...then get the corresponding date and therefore rate?
isn't there any similar way of doin it, i mean is there no way of writing a select statement that selects rate where dif between todays date and dte is smallest????
-
Apr 11th, 2005, 05:43 AM
#4
Addicted Member
Re: comparing dates
Could you not sort your table into ascending order by date using SORT BY name of date column ASC. Then.. get todays date, search for it in the table then surely the next record (.movenext) will be the closest to todays date?
BIOSTALL
-
Apr 11th, 2005, 05:44 AM
#5
Hyperactive Member
Re: comparing dates
unfortunately not, the only way to select the smallest value from an array or any collection of values is by looping through all of them
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Apr 11th, 2005, 05:46 AM
#6
Thread Starter
Hyperactive Member
Re: comparing dates
 Originally Posted by BIOSTALL
Could you not sort your table into ascending order by date using SORT BY name of date column ASC. Then.. get todays date, search for it in the table then surely the next record (.movenext) will be the closest to todays date?
BIOSTALL
yeah i think so, il try and let u know
-
Apr 11th, 2005, 05:47 AM
#7
Hyperactive Member
Re: comparing dates
@Biostall:
using a sort would work, however i was under the impression she was doing this entirely from vb, can you sort the columns from there?
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Apr 11th, 2005, 05:49 AM
#8
Addicted Member
Re: comparing dates
In an sql query you can. And i meant ORDER BY, not SORT BY, sorry
BIOSTALL
-
Apr 11th, 2005, 06:06 AM
#9
Re: comparing dates
Hold the phone, folks. You can do this with a query like the following:
VB Code:
strSQL = "SELECT RateField FROM TheTable " _
& " WHERE DateField = (SELECT MAX(DateField) FROM TheTable " _
& " WHERE DateField <= #" & Format$(Date, "m/d/yyyy") & "#"
"It's cold gin time again ..."
Check out my website here.
-
Apr 11th, 2005, 06:54 AM
#10
Thread Starter
Hyperactive Member
Re: comparing dates resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|