Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript - Datediff

Status
Not open for further replies.

disord3r

Programmer
Apr 12, 2002
189
US
There's something very strange going on with what seems to be a simple comparison involving DateDiff. Here's the code:

if DateDiff(&quot;d&quot;, cdateonly, date()) < timespent then
Response.Write datediff(&quot;d&quot;, cdateonly, date()) & &quot; < &quot; & timespent
end if

Looks fairly simple. Using the datediff function, if the number of days between &quot;cdateonly&quot; and the current date (using the date() function) is LESS THAN this variable called &quot;timespent&quot;, it should print &quot;x < timespent&quot;, where X is the result of the datediff() operation and timespent is some value received from a HTML form.

Let's say &quot;cdateonly&quot; is '1/1/2002' and &quot;timespent&quot; is '10'. The result of DateDiff would be 63. Because 63 is not less than 10, the response.write line should not be executed. Problem is, this is the kind of output I'm getting:

623 < 10
812 < 10
265 < 10
264 < 10
264 < 10
263 < 10

It seems to think EVERYTHING is less than &quot;timespent&quot;, whether it is or not. What gives? Thanks in advance!!
 
Problem solved.

Changing...

if DateDiff(&quot;d&quot;, cdateonly, date()) < timespent then

...to...

if DateDiff(&quot;d&quot;, cdateonly, date()) < int(timespent) then

...did the trick. Even though the type attribute for the timespent input box in the HTML form was set to &quot;number&quot;, the ASP script still treated it as text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top