Date Difference

1. Senior Member
Join Date
Dec 1969
Posts
511

## Date Difference

Hi,<BR><BR>Im using the following code to determine the difference in date. However it appears that if the value is a two character number (-71 for instance) It believe thats the If statement for being more than -365 is true. Any ideas are appreciated. <BR><BR><BR>dtNow = Date()<BR> dtNow = FormatDateTime(dtNow, vbShortDate)<BR> IF ISDate(enddate)Then<BR> enddate = FormatDateTime(enddate, vbShortDate)<BR> iDaysDifference = DateDiff("d", enddate, dtNow)<BR> Else<BR> iDaysDifference = 0<BR> END IF<BR>If inStrGrp(Request.Form("enddate"),"!£\$%^&*()}{][~@#:;?&#062;&#060;,&#124¬`") = True OR enddate = "" Or enddate = " " OR Len(enddate) &#060; 2 OR iDaysDifference =&#062; 0 Then<BR> enddateerror = True<BR> errorlist = errorlist + "The End Date field is empty or contains an invalid character,date or a date that is before today"<BR> enddate = "Re-enter Please"<BR> ELSEIF iDaysDifference &#062; "-365" Then<BR> enddateerror = True<BR> errorlist = errorlist + "The maximum time is one year away for an end date" <BR> END IF

2. Senior Member
Join Date
Dec 1969
Posts
1,032

## RE: Date Difference

&nbsp;<BR>1, -71 is more than -365 !!<BR><BR>2, <BR><BR>ELSEIF iDaysDifference &#062; "-365" Then<BR>enddateerror = True<BR>errorlist = errorlist + "The maximum time is one year away for an end date" <BR>END IF<BR><BR><BR>why do you use " marks around a number ??<BR><BR><BR>3,<BR><BR>ELSEIF iDaysDifference &#062; "-365" <BR><BR><BR>wouldnt it be &#060; - 365 ??<BR><BR>I would turn around the way you calculate datediff , to return a positive value , its far easier to work with <BR><BR>jon

3. Senior Member
Join Date
Dec 1969
Posts
511

## RE: Date Difference

changing it to a positive value fixed all my problems but ill naswer these below anyway.<BR><BR>1. In maths yes but for some reason it wasnt seeing at that way. It was seeing -76 as higher than -75<BR><BR>2. Tried with and without just trying to get it to work.<BR><BR>3. putting &#060; -365 caused it not to call up an error when it was actually more than a year away<BR><BR>anywy poitive value seems to haev worked.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•