Click to See Complete Forum and Search --> : getting the rows of dates near today date


pelegk1
02-07-2006, 03:56 PM
for example i have
1/2/2004
5/2/1955
30/2/1978

and if today for example is 7/2/2006
then i want to get all the rows with the date (by date i mean day+month)
that are in the range of +-3 days from todays date(day+month)
in this case i will recive only the row with 5/2/1955
how do i do this?
thnaks in advance
peleg

TheBearMay
02-08-2006, 07:16 AM
Not at my "home" PC so I can't test this but this should be close enough to point you in the right direction assuming your dates are loaded in an array named dateArray (simple enough to modify to use row/fetch logic):

Note: I'm using language=JScript so if you're using VB you'll need to translate

var tDay= new Date();
var tmpDay=tDay.getDate()+3;
var tmpYear=tDay.getFullYear()+1;
tmpMonth=tDay.getMonth();
var ceilDate = new Date(tmpYear,tmpMonth,tmpDay);
var tmpDay=tDay.getDate()-3;
var floorDate = new Date(tmpYear,tmpMonth,tmpDay);
for (i=0;i<dateArray.length;i++){
tmpDay = dateArray[i].substr(0,dateArray[i].indexOf("/")-1);
tmpMonth = dateArray[i].substr(dateArray[i].indexOf("/"),dateArray[i].lastIndexOf("/")-dateArray[i].indexOf("/"));
if (new Date(tmpYear,tmpMonth,tmpDay) >= floorDate && new Date(tmpYear,tmpMonth,tmpDay) <= ceilDate) alert(dateArray[i]);
}