Below is a copy and paste from my immediate window in VS2010. Notice that the string representations of the Now function are the same, but their binary representations are vastly different. Unwrapping the Now function from CDate makes no difference. Why?
?CDate(Now)
1/8/2013 10:06:46 AM
?CDate(Now.ToString)
1/8/2013 10:06:52 AM
?CDate(Now.ToString).ToBinary
634932364230000000
?CDate(Now).ToBinary
-8588439384563815032
?Now.ToBinary
-8588439380551725996
Notice that I am now working with the exact same time on every line. Why do I get the “abberant” numerical result when I use the ToString function?
?Now.ToBinary
-8588439366264255565
?datetime.FromBinary(-8588439366264255565)
1/8/2013 10:37:39 AM
?datetime.FromBinary(-8588439366264255565).ToBinary
-8588439366264255565
?cdate(datetime.FromBinary(-8588439366264255565).ToString ).ToBinary
634932382590000000
?CDate(datetime.FromBinary(-8588439366264255565)).ToBinary
-8588439366264255565
It’s because DateTime.Now has millisecond precision, but when you call ToString, milliseconds are not printed. The two dates are not the same anymore.
If you print the date with a format which includes milliseconds, you will get the same result:
Output: