Click to See Complete Forum and Search --> : date calculation


janice
07-29-2003, 08:33 AM
good friends, I have a little problem.
I have 3 dates: trainingDate, firstDate, 2ndDate.
I want to determine the least date of the 3 and add one year to it and call it expirationDate.
For instance, trainingDate = 01/01/2003, firstDate, 02/01/2003, and 2ndDate = 03/01/2003.
Here, the least is trainingDate.
I need to take this trainingDate and add one year to it.
Here is my code:
thanks in advance
if dateDiff("d", trainingDate, secondDate)<0 then
'a negative value from datediff means the first value is later than the second
if dateDiff("d",secondDate,thirdDate)<0 then
thirdDate=DateAdd("yyyy",1,thirdDate)
response.write thirdDate
else
secondDate=DateAdd("yyyy",1,secondDate)
response.write secondDate

end if
else
if dateDiff("d",trainingDate,thirdDate)<0 then
thirdDate=DateAdd("yyyy",1,thirdDate)
else
trainingDate=DateAdd("yyyy",1,trainingDate)
response.write secondDate

end if
end if

janice
07-29-2003, 10:48 PM
hello Dave!
Thank you for your time and help.
Your code will work as it is if one, we have only one row of date values in our database to compare with, and two if we are hardcoding the date values.
I apologize if I wasn't clear about this.
These dates are being retrieved from the db.
So date values get inserted each row at a time.
If we have say 3 rows containing various date values as will be the case with this table, hardcoding date values won't work.
Can you think of any other way I can do this, please?

janice
07-30-2003, 07:37 AM
oh, I see!
Thanks again!!

janice
07-31-2003, 10:05 AM
hi again!
I am probably making this harder than it should be.
We know that by default, trainingDate(lowestDate) is always goinhg to be the earliest date.
So it is like. first training date is 01/01/2003.
If you can't make that, the next earliest is 02/02/2003.
If you still can't make that, the next earliest date is 05/01/2003. Of course these dates are made up but I am using them as examples.

So given that the earliest (lowest date) is always going to be trainingDate, why can't this work:

Dim lowestDate,expireDate
do while not rst.eof
lowestDate = DateValue(rst("trainingDate").Value)
expireDate = DateAdd("yyyy", 1, lowestDate)
rst.movenext
loop

janice
07-31-2003, 11:21 PM
ok, let's say that i have 2 rows of data (the table will grow to more than 2 rows):
lowestDate
trainingDate 2ndDate 3rdDate expDate
01/01/2003 02/01/2003 03/01/2003 07/01/2004
05/01/2003 06/01/2003 07/01/2003 07/01/2004

From the above sample date, if I use the code I posted here, you can see that expiration date for both rows is the same.
It should be 01/01/2004 for first row and 07/01/2004 for second.

janice
08-01-2003, 09:23 AM
The problem isn't with the code that you've shown.

Interesting observation!
What do you think could be the problem?
Do I need to change the data types of these fields to character data type versus datetime data type?

janice
08-01-2003, 09:40 PM
oh, I see.
well, what was all the code I wrote.
The only other code I wrote was to print it out like so:

.Write "<td>" & expireDate & "</td>"
If you don't mind, can you suggest what else I need to add to make it work, please?.
I thought that since I was just adding one year to trainingDate, the lowest date, that that code would be enough.

janice
08-02-2003, 12:08 PM
ok, I bow!
It is working now like a dream.
Thank you, thank you, and thank you!