T
tohear
ToOADate and FromOADate don't handle negative dates with time parts
correctly. Negative dates with no time parts are OK. (Note: In COM
date "zero" is 12/30/1899).
Does anyone know if these are known bugs and if they will be
corrected? In the meantime I strongly recommend writing your own
functions if you work with negative time. In particular if you've
converted a vb6 project to dotnet.
-----------------------
ToOADate converts negative "round" dates ok :
#12/29/1899#.ToOADate ' = -1 OK
#12/28/1899#.ToOADate ' = -2 OK
#12/27/1899#.ToOADate ' = -3 OK
However negative dates with a time part don't convert correctly :
#12/29/1899 11:59:59 PM#.ToOADate ' = ~-2 NOT OK should be ~0
#12/28/1899 11:59:59 PM#.ToOADate ' = ~-3 NOT OK should be ~-1
#12/27/1899 11:59:59 PM#.ToOADate ' = ~-4 NOT OK should be ~-2
Playing around with other times of day it seems this is because the
code in ToOADate is *subtracting* the time part from the negative date
rather than adding it.
System.DateTime.FromOADate converts negative round numbers ok :
FromOADate(-1) ' = #12/29/1899# OK
FromOADate(-2) ' = #12/28/1899# OK
FromOADate(-2) ' = #12/27/1899# OK
However negative dates with a time part don't convert correctly :
FromOADate(-0.999) ' = ~#12/31/1899# NOT OK, should be ~#12/29/1899#.
FromOADate(-1.999) ' = ~#12/30/1899# NOT OK, should be ~#12/28/1899#.
FromOADate(-2.999) ' = ~#12/29/1899# NOT OK, should be ~#12/27/1899#.
Playing around with other numbers it seems this is because the code in
FromOADate is *adding* the fractional part of the number to the date
rather than subtracting it.
correctly. Negative dates with no time parts are OK. (Note: In COM
date "zero" is 12/30/1899).
Does anyone know if these are known bugs and if they will be
corrected? In the meantime I strongly recommend writing your own
functions if you work with negative time. In particular if you've
converted a vb6 project to dotnet.
-----------------------
ToOADate converts negative "round" dates ok :
#12/29/1899#.ToOADate ' = -1 OK
#12/28/1899#.ToOADate ' = -2 OK
#12/27/1899#.ToOADate ' = -3 OK
However negative dates with a time part don't convert correctly :
#12/29/1899 11:59:59 PM#.ToOADate ' = ~-2 NOT OK should be ~0
#12/28/1899 11:59:59 PM#.ToOADate ' = ~-3 NOT OK should be ~-1
#12/27/1899 11:59:59 PM#.ToOADate ' = ~-4 NOT OK should be ~-2
Playing around with other times of day it seems this is because the
code in ToOADate is *subtracting* the time part from the negative date
rather than adding it.
System.DateTime.FromOADate converts negative round numbers ok :
FromOADate(-1) ' = #12/29/1899# OK
FromOADate(-2) ' = #12/28/1899# OK
FromOADate(-2) ' = #12/27/1899# OK
However negative dates with a time part don't convert correctly :
FromOADate(-0.999) ' = ~#12/31/1899# NOT OK, should be ~#12/29/1899#.
FromOADate(-1.999) ' = ~#12/30/1899# NOT OK, should be ~#12/28/1899#.
FromOADate(-2.999) ' = ~#12/29/1899# NOT OK, should be ~#12/27/1899#.
Playing around with other numbers it seems this is because the code in
FromOADate is *adding* the fractional part of the number to the date
rather than subtracting it.