473,789 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Major bug in System.Date.ToO ADate and FromOADate

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.
Nov 20 '05 #1
11 10420
"tohear" <ti****@ohear.c om> schrieb
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 :

In VB6, I also misunderstood how it works, and there it worked the same way
as it does now in VB.Net. The simple answer is: It's not a bug, but it's
how it works: :-)
The Integer part is the day based on #12/30/1899#. The fractional part is
the time.

#12/29/1899 11:59:59 PM#.ToOADate ' = ~-2 NOT OK should be ~0
It returns -1.9999884259259 3. I think this is important in this case.

-1.9999884259259 3 has to interpreted this way:
-1 is the day: #12/29/1899# minus 1 day = #12/28/1899#
The fractional part is the time: 0.9999884259259 3 is 11:59:59 PM

That's also true for the other cases.
#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 ^^ probably -3 :-)
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.


Well, FromOADate is consistent with ToOADate. The behavior is the same as
explained above.
--
Armin
Nov 20 '05 #2
"tohear" <ti****@ohear.c om> schrieb
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 :

In VB6, I also misunderstood how it works, and there it worked the same way
as it does now in VB.Net. The simple answer is: It's not a bug, but it's
how it works: :-)
The Integer part is the day based on #12/30/1899#. The fractional part is
the time.

#12/29/1899 11:59:59 PM#.ToOADate ' = ~-2 NOT OK should be ~0
It returns -1.9999884259259 3. I think this is important in this case.

-1.9999884259259 3 has to interpreted this way:
-1 is the day: #12/29/1899# minus 1 day = #12/28/1899#
The fractional part is the time: 0.9999884259259 3 is 11:59:59 PM

That's also true for the other cases.
#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 ^^ probably -3 :-)
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.


Well, FromOADate is consistent with ToOADate. The behavior is the same as
explained above.
--
Armin
Nov 20 '05 #3
Hello Armin,

I've ran some tests on VB6 and you're correct that it mostly behaves the
same way: 1 second before the end of 12/29/1899 (#12/29/1899 11:59:59
PM#) is in fact considered as 1 second before the start of 12/28/1899
rather than 12/30/1899. So it's "logical" that it should be
-1.9999884259259 3. I was wrong to believe this was a bug.

However there remains a problem :

in VB6: CDbl(Cdate(-1.5)) = -1.5
and : CDbl(Cdate(-0.5)) = -0.5

In dotnet : FromOADate(-1.5).ToOADate = -1.5
but : FromOADate(-0.5).ToOADate = 0.5 (!!!)

So it's as if doubles smaller than 0 and bigger than -1 are no longer
converted to COM dates properly and instead turned into positive values.

Any suggestions as to how values < 0 and > -1 can still be used?

Thanks,

Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Hello Armin,

I've ran some tests on VB6 and you're correct that it mostly behaves the
same way: 1 second before the end of 12/29/1899 (#12/29/1899 11:59:59
PM#) is in fact considered as 1 second before the start of 12/28/1899
rather than 12/30/1899. So it's "logical" that it should be
-1.9999884259259 3. I was wrong to believe this was a bug.

However there remains a problem :

in VB6: CDbl(Cdate(-1.5)) = -1.5
and : CDbl(Cdate(-0.5)) = -0.5

In dotnet : FromOADate(-1.5).ToOADate = -1.5
but : FromOADate(-0.5).ToOADate = 0.5 (!!!)

So it's as if doubles smaller than 0 and bigger than -1 are no longer
converted to COM dates properly and instead turned into positive values.

Any suggestions as to how values < 0 and > -1 can still be used?

Thanks,

Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5
I think you will find that if you pass actual date/time values you will be
much happier with the results then if you pass things that acre not actually
dates at all?
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Timothy O'Hear" <ti****@ohear.c om> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
Hello Armin,

I've ran some tests on VB6 and you're correct that it mostly behaves the
same way: 1 second before the end of 12/29/1899 (#12/29/1899 11:59:59
PM#) is in fact considered as 1 second before the start of 12/28/1899
rather than 12/30/1899. So it's "logical" that it should be
-1.9999884259259 3. I was wrong to believe this was a bug.

However there remains a problem :

in VB6: CDbl(Cdate(-1.5)) = -1.5
and : CDbl(Cdate(-0.5)) = -0.5

In dotnet : FromOADate(-1.5).ToOADate = -1.5
but : FromOADate(-0.5).ToOADate = 0.5 (!!!)

So it's as if doubles smaller than 0 and bigger than -1 are no longer
converted to COM dates properly and instead turned into positive values.

Any suggestions as to how values < 0 and > -1 can still be used?

Thanks,

Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6
Hello MichKa,

I wouldn't touch OADates with a 10 foot pole if I had the choice.
However the code was originally developed in VB6 so I'm somewhat hostage
to dates becoming doubles that may become dates again, bar a substantial
redesign.

If I've understood this correctly, use of COM dates/times from -23:59:59
to -00:00:01 (which VB6 was perfectly happy with) requires that
To/FromOADate handles the interval ]-1;0[ which it doesn't seem to do.

Would you say that it's by design that FromOADate(-0.5).ToOADate = 0.5
whereas FromOADate(-1.5).ToOADate = -1.5, or is this a bug?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7
"Timothy O'Hear" <ti****@ohear.c om> schrieb
Hello Armin,

I've ran some tests on VB6 and you're correct that it mostly behaves
the same way: 1 second before the end of 12/29/1899 (#12/29/1899
11:59:59 PM#) is in fact considered as 1 second before the start of
12/28/1899 rather than 12/30/1899. So it's "logical" that it should
be -1.9999884259259 3. I was wrong to believe this was a bug.

However there remains a problem :

in VB6: CDbl(Cdate(-1.5)) = -1.5
and : CDbl(Cdate(-0.5)) = -0.5

In dotnet : FromOADate(-1.5).ToOADate = -1.5
but : FromOADate(-0.5).ToOADate = 0.5 (!!!)

So it's as if doubles smaller than 0 and bigger than -1 are no
longer converted to COM dates properly and instead turned into
positive values.

Any suggestions as to how values < 0 and > -1 can still be used?

-0.5 and +0.5 are equal because -0 and +0 are equal. If the day is zero, it
is #12/30/1899#. Then add the fractional part, i.e. #12:00#. Result:
#12/30/1899 12:00#
--
Armin

Nov 20 '05 #8
I think you will find that if you pass actual date/time values you will be
much happier with the results then if you pass things that acre not actually
dates at all?
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Timothy O'Hear" <ti****@ohear.c om> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
Hello Armin,

I've ran some tests on VB6 and you're correct that it mostly behaves the
same way: 1 second before the end of 12/29/1899 (#12/29/1899 11:59:59
PM#) is in fact considered as 1 second before the start of 12/28/1899
rather than 12/30/1899. So it's "logical" that it should be
-1.9999884259259 3. I was wrong to believe this was a bug.

However there remains a problem :

in VB6: CDbl(Cdate(-1.5)) = -1.5
and : CDbl(Cdate(-0.5)) = -0.5

In dotnet : FromOADate(-1.5).ToOADate = -1.5
but : FromOADate(-0.5).ToOADate = 0.5 (!!!)

So it's as if doubles smaller than 0 and bigger than -1 are no longer
converted to COM dates properly and instead turned into positive values.

Any suggestions as to how values < 0 and > -1 can still be used?

Thanks,

Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #9
Hello MichKa,

I wouldn't touch OADates with a 10 foot pole if I had the choice.
However the code was originally developed in VB6 so I'm somewhat hostage
to dates becoming doubles that may become dates again, bar a substantial
redesign.

If I've understood this correctly, use of COM dates/times from -23:59:59
to -00:00:01 (which VB6 was perfectly happy with) requires that
To/FromOADate handles the interval ]-1;0[ which it doesn't seem to do.

Would you say that it's by design that FromOADate(-0.5).ToOADate = 0.5
whereas FromOADate(-1.5).ToOADate = -1.5, or is this a bug?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15827
by: Omer kamal | last post by:
Dear all, I want to save my data into MS Access database Table which consist of some fields with short date and short time formats. I try to save data in to the said table and I am getting error that my SQL statment is not correct. string strSQL = @"INSERT INTO Activities ( Task,Day,Start,Finish ) VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;
8
4715
by: Tim | last post by:
Does anyone know how to convert a date to the hundred year date format. For example, how would i convert 8/11/2004 to its hundred year date format. Thanks! Tim
0
1456
by: tohear | last post by:
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. -----------------------
1
15303
by: Kenny | last post by:
I am having issues with the "Date.ToOADate" method in VB .NET. I understand that in VB6 the function DateSerial gives an internal representation of the date. When I use the DateSerial method in VB .Net, dragging the mouse over to the statement, VB .NET reports the following "Conversion from 'Date' to "Double' requires calling the 'Date.ToOAdate' method. When I tyoe this method in, the syntax checker undelines
2
1919
by: Robin Tucker | last post by:
I have an active-X control (ATl/C++) that expects a date as Variant Time (a double). How can I convert a date in VB.NET into such a double? Any help would be much appreciated. thanks.
4
11498
by: sam | last post by:
Possible convert VB 6 to VB.Net 1.1 for date serial function? Example, Calendar_Date = DateSerial(1900+(Julian_Date/1000), 1,Julian_Date Mod 1000) ? Calendar_Date and Julian_Date are input variable. Please advise.
4
5315
by: Peter | last post by:
What is the easiest way to convert serialdate (like excel has) into real date in VB.NET? Thank You Peter
2
7070
by: TofuTheGreat | last post by:
I'm using "Now.ToOADate" for a record timestamp in a small database app (it's what I want to do so don't try to disuade me ;-D). Anyway. I store the value of Now.ToOADate in a string field in the database (16 character field on a SQL server to be exact). Is there a way of converting the text value from that field back into a readable date/time? For example if a date is stored in the 16 character field as the OLE Automation format...
1
9569
by: =?Utf-8?B?RGFwcGVyRGFuSEBub3NwYW0ubm9zcGFt?= | last post by:
Given the example below, can someone explain why TimeSpan.TotalDays gives a different result than subtracting 2 DateTime.ToOADates? I am completely stumped. Thanks in advance, Dan Example Output: start: 1/1/2007 12:00:00 AM end : 1/1/2007 1:00:00 AM
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.