Reputation: 350
In classic ASP, I am unable to use DateAdd() with variables. I see no reason why this should work.
strTargetDate=DateAdd("d",visitDate,followDate)
visitDate is an incremental value -- 30, 60, 90, 180 etc. followDate is an actual date. However, I receive a type mismatch error using this code. Shouldn't this work??
Upvotes: 0
Views: 2089
Reputation: 38745
Either visitDate isn't/can't be converted to a number, or followDate isn't/can't be converted to a date. So check the TypeName() of your input and pay attention to date formats.
Partly to show facts against @Ken's speculations:
>> s = "string"
>> WScript.Echo 0, s, TypeName(s)
>> s = DateAdd("d", 1, Now)
>> WScript.Echo 1, s, TypeName(s)
>> s = DateAdd("d", "1", CStr(now))
>> WScript.Echo 2, s, TypeName(s)
>> s = DateAdd("d", 1, "20/10/2013")
>>
0 string String
1 24.10.2013 17:05:54 Date
2 24.10.2013 17:05:54 Date
>> s = DateAdd("d", 1, "32.13.1")
>>
Error Number: 13
Error Description: Type mismatch
Update wrt comment:
As computations involving Null should propagate Null, this
>> WScript.Echo TypeName(DateAdd("d", 1, Null))
>>
Null
>>
is no surprise. While you should handle Nulls for your DateAdd() in a way appropriate to your application, they are not the cause for the type mismatch.
Empty strings (""), however, could well be the culprits:
>> WScript.Echo TypeName(DateAdd("d", 1, ""))
>>
Error Number: 13
Error Description: Type mismatch
>>
Upvotes: 2