Dr
Thu Nov 03 10:56:17 CST 2005
JRS: In article <1130934124.816534.254240@g43g2000cwa.googlegroups.com>
, dated Wed, 2 Nov 2005 04:22:04, seen in news:microsoft.public.scriptin
g.vbscript, Michael Jervis <mjervis@gmail.com> posted :
>Small VBS to demonstrate an issue I have with the VBS DateAdd function:
>
>msgbox CDate("23/10/2005 22:15:00") = DateAdd("h", 22, DateAdd("n", 15,
>CDate("23/10/2005")))
>
>This pops up a message box with False in it.
>
>Any suggestion as to why?
>
>This returns true:
>
>msgbox CDate("23/10/2005 22:15:00") = CDate(CStr(DateAdd("h", 22,
>DateAdd("n", 15, CDate("23/10/2005")))
>
>(UK Locale!)
Dates are stored, in IEEE Doubles IIRC, in units of Days since 0 =
Saturday 1899-12-30 00:00 local.
Therefore, neither 22 hours, nor 15 minutes, nor 22:15:00, can be stored
exactly. MsgBox the difference, rather than the equality, and you may
see non-zero.
If you want accuracy in minutes, multiply by 1440 and use exact minutes
or round to the nearest.
CDate("03/11/2005") is unsafe, since there's a risk of going American
and getting Feb 11 - CDate("03 Nov 2005") is safe everywhere.
To add 22h 15m to a date D, I'd use D + 22/14 + 15/1440 or D + 22.25/24.
See <URL:
http://www.merlyn.demon.co.uk/vb-dates.htm> .
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:
http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:
http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.