Sunday, October 29, 2006

asp bug in DateAdd

This bug relates to the return value of DateAdd when presented with a date-time object which doesn't have date info, but only time info. Caused our schedule page to show 12/31/1899 instead of 12 AM for midnight.

Copy-paste from a mail I wrote to RI about this:

Adding a (fictitious) date part to the
(relevant) time part seems to
solve the problem when it is a simple string as in testdatetime.asp

In the actual radiosai.asp code, things get more sticky.

There, the time part is a Date/Time formatted recordset field.

response.write(rsSGH("dps_Time"))
yields 10/26/2006 1:00:00 AM which already has a date part tacked on! And the
buggy part is, when the time crosses 6.30 pm, the date part vanishes!

What I did was to convert it into a string using the built-in type conversions
by just adding a space in front of it.

d=" " & rsSGH("dps_Time")
DateAdd("n",addTime,d)
for the times upto midnight and

d="27-Oct-2006 " & rsSGH("dps_Time")
DateAdd("n",addTime,d)
for the times midnight and later.

instead of DateAdd("n",addTime,rsSGH("dps_Time"))

No comments:

Post a Comment