[thelist] MSSQL: adding integer to time yields date?
Joshua Olson
joshua at waetech.com
Mon Nov 28 13:59:50 CST 2005
> -----Original Message-----
> From: Canfield, Joel
> Sent: Monday, November 28, 2005 12:54 PM
>
> Query
>
> select StartTime, Length from Events
>
> yields
>
> 1900-01-01 20:00:00 4.0
>
> StartTime is smalldatetime, Length is float (not int, as I originally
> stated)
>
> This VBScript
>
> datEventEndTime = DateAdd("h",intEventLength,datEventStartTime)
>
> results in 12/31/1899
Joel,
I just ran the following code in ASP/VBScript:
dateval = CDate("1900-01-01 20:00:00")
Response.Write DateAdd("h",4,dateval)
The output was:
1/2/1900
Ok, so this is just as I'd expect.
Then I changed the code to this:
dateval = CDate("20:00:00")
Response.Write DateAdd("h",4,dateval)
The output was:
12/31/1899
Then I changed the code to this:
dateval = CDate("20:00:00")
Response.Write DateAdd("h",3,dateval)
The output was:
11:00:00 PM
It seems that the VBScript engine assumes 12/31/1899 when a date value is
only has the time portion defined. So, when you then display a date, the
date is converted back to a string... if the time is midnight, it presumes
you want to see the date (12/31/1899), otherwise it displays the time. Or
so it seems. :-)
I don't think this has anything to do with MSSQL.
<><><><><><><><><><>
Joshua L. Olson
WAE Tech Inc.
http://www.waetech.com/
Phone: 706.210.0168
Fax: 413.812.4864
Monitor bandwidth usage on IIS6 in real-time:
http://www.waetech.com/services/iisbm/
More information about the thelist
mailing list