inamori said:
I face that problems
07/01/2003 06/30/2006 ---------> it should be 3
01/01/2003 02/28/2005 --------->could i get 2 years and 2 months
01/01/2003 03/01/2005 --------->could i get 2 years and 2 months
and 1 day
Could you explain why these aren't the correct results?
The difference between 7/1/2003 and 6/30/2006 is:
3 years, 11 months, and 29 days
The difference between 1/1/2003 and 2/28/2005 is:
2 years, 1 months, and 27 days
The difference between 1/1/2003 and 3/1/2005 is:
2 years, 2 months, and 0 days
What is the logic used to determine when to add one day to the results?
Should the difference between 07/01/2003 and 07/01/2003 be 1 day? How about
07/01 and 07/02?
This is the code I used to get the above results:
<%
dim arDates(2,1), iYrs, iMths, iDays, i
arDates(0,0) = #2003-07-01#
arDates(0,1) = #2006-06-30#
arDates(1,0) = #2003-01-01#
arDates(1,1) = #2005-02-28#
arDates(2,0) = #2003-01-01#
arDates(2,1) = #2005-03-01#
for i = 0 to 2
Response.Write "The difference between " & arDates(i,0) & _
" and " & arDates(i,1) & " is: "
iYrs=DateDiff("yyyy",arDates(i,0),arDates(i,1))
Response.Write iYrs & " years, "
iMths=DateDiff("m",arDates(i,0),arDates(i,1))
if iMths < 12*iYrs then iYrs = iYrs - 1
if iMths - 12*iYrs < 0 then
Response.Write " 0 months, and "
else
Response.Write iMths - 12*iYrs & " months, and "
end if
iDays = DateDiff("d",arDates(i,0), _
DateAdd("m", -1*iMths, arDates(i,1)))
if iDays < 1 then iDays = 0
Response.Write iDays & " days"
Response.Write "<BR>"
next
%>
Bob Barrows