PC Review


Reply
Thread Tools Rate Thread

Array of double, must be also able to hold DateTime

 
 
Sonnich Jensen
Guest
Posts: n/a
 
      9th May 2011
Hi all

I need a way to have a

public List<double> XValues = new List<double>();

which also can hold DateTime values.

How can I convert a double to DateTime and viseversa?
I tried today, but did not find a proper way

Thx
Sonnich
 
Reply With Quote
 
 
 
 
Jeff Gaines
Guest
Posts: n/a
 
      9th May 2011
On 09/05/2011 in message
<31b96831-6223-4936-a648-(E-Mail Removed)> Sonnich
Jensen wrote:

>Hi all
>
>I need a way to have a
>
>public List<double> XValues = new List<double>();
>
>which also can hold DateTime values.
>
>How can I convert a double to DateTime and viseversa?
>I tried today, but did not find a proper way
>
>Thx
>Sonnich


DateTime.ToBinary() gets you to an Int64, would that help?

--
Jeff Gaines Wiltshire UK
There are 3 types of people in this world. Those who can count, and those
who can't.
 
Reply With Quote
 
Rick Lones
Guest
Posts: n/a
 
      9th May 2011
Sonnich Jensen wrote:
> Hi all
>
> I need a way to have a
>
> public List<double> XValues = new List<double>();
>
> which also can hold DateTime values.
>
> How can I convert a double to DateTime and viseversa?
> I tried today, but did not find a proper way
>
> Thx
> Sonnich


Well, if your double represents an offset in (100ns) ticks from some known
starting date/time, then that would be a way. But a long int would be more
appropriate since the entire 64 bits would be available. With a double you must
restrict yourself to no more significant bits than the mantissa can accomodate.

-rick-
 
Reply With Quote
 
Sonnich Jensen
Guest
Posts: n/a
 
      9th May 2011
On May 9, 8:47*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
> On 5/9/11 8:57 AM, Sonnich Jensen wrote:
>
> > Hi all

>
> > I need a way to have a

>
> > public List<double> *XValues = new List<double>();

>
> > which also can hold DateTime values.

>
> > How can I convert a double to DateTime and viseversa?
> > I tried today, but did not find a proper way

>
> It can be done, per the other two replies and even other techniques.
>
> But I would advise against it. *If you are trying to store values of
> type double and DateTime in the same data structure and yet have no
> readily convenient way to convert between double and DateTime, then you
> have a fundamental design error.
>
> Instead of trying to store two completely unrelated types in the same
> data structure, you should fix your design so that doing so isn't necessary.
>
> If you would explain at a higher level what it is you're actually trying
> to do, then we can assist you with that.
>
> Pete


Thanks to all of you.

I found my solution in ToOADate() and a few additional functions.
I have a database, where I have my dates in Deplhi format, and I guess
that ToOADate() and FromOADate() can be useful.

From delphi help:
Most VCL objects represent date and time values using the TDateTime
type. The integral part of a TDateTime value is the number of days
that have passed since 12/30/1899. The fractional part of a TDateTime
value is fraction of a 24 hour day that has elapsed.

Following are some examples of TDateTime values and their
corresponding dates and times:

0 12/30/1899 12:00 am
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am


 
Reply With Quote
 
Rick Lones
Guest
Posts: n/a
 
      9th May 2011
Sonnich Jensen wrote:
> On May 9, 8:47 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
>> On 5/9/11 8:57 AM, Sonnich Jensen wrote:
>>
>>> Hi all
>>> I need a way to have a
>>> public List<double> XValues = new List<double>();
>>> which also can hold DateTime values.
>>> How can I convert a double to DateTime and viseversa?
>>> I tried today, but did not find a proper way

>> It can be done, per the other two replies and even other techniques.
>>
>> But I would advise against it. If you are trying to store values of
>> type double and DateTime in the same data structure and yet have no
>> readily convenient way to convert between double and DateTime, then you
>> have a fundamental design error.
>>
>> Instead of trying to store two completely unrelated types in the same
>> data structure, you should fix your design so that doing so isn't necessary.
>>
>> If you would explain at a higher level what it is you're actually trying
>> to do, then we can assist you with that.
>>
>> Pete

>
> Thanks to all of you.
>
> I found my solution in ToOADate() and a few additional functions.
> I have a database, where I have my dates in Deplhi format, and I guess
> that ToOADate() and FromOADate() can be useful.
>
> From delphi help:
> Most VCL objects represent date and time values using the TDateTime
> type. The integral part of a TDateTime value is the number of days
> that have passed since 12/30/1899. The fractional part of a TDateTime
> value is fraction of a 24 hour day that has elapsed.
>
> Following are some examples of TDateTime values and their
> corresponding dates and times:
>
> 0 12/30/1899 12:00 am
> 2.75 1/1/1900 6:00 pm
> -1.25 12/29/1899 6:00 am
> 35065 1/1/1996 12:00 am
>


Not recommended. I recall a problem with VB3, which stored dates as floats
using some such similar scheme. Because floating-point fractional values do not
always have a precise representation it could be the case that if you took a
starting datetime and added, e.g., 5 seconds to it you would not necessarily get
the same result (meaning one which compared as equal in an IF statement) as you
would by taking the same starting datetime and, e.g., adding 4 seconds to it and
then adding 1 second. I considered this a bug, although the MS support person I
reported it to did not . . . YMMV on that, but this can be the kind of issue you
may buy into with such an innapropriate (IMO) representation.

-rick-
 
Reply With Quote
 
James A. Fortune
Guest
Posts: n/a
 
      10th May 2011
On May 9, 2:40*pm, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
> On May 9, 8:47*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
>
>
>
> > On 5/9/11 8:57 AM, Sonnich Jensen wrote:

>
> > > Hi all

>
> > > I need a way to have a

>
> > > public List<double> *XValues = new List<double>();

>
> > > which also can hold DateTime values.

>
> > > How can I convert a double to DateTime and viseversa?
> > > I tried today, but did not find a proper way

>
> > It can be done, per the other two replies and even other techniques.

>
> > But I would advise against it. *If you are trying to store values of
> > type double and DateTime in the same data structure and yet have no
> > readily convenient way to convert between double and DateTime, then you
> > have a fundamental design error.

>
> > Instead of trying to store two completely unrelated types in the same
> > data structure, you should fix your design so that doing so isn't necessary.

>
> > If you would explain at a higher level what it is you're actually trying
> > to do, then we can assist you with that.

>
> > Pete

>
> Thanks to all of you.
>
> I found my solution in ToOADate() and a few additional functions.
> I have a database, where I have my dates in Deplhi format, and I guess
> that ToOADate() *and FromOADate() can be useful.
>
> From delphi help:
> Most VCL objects represent date and time values using the TDateTime
> type. The integral part of a TDateTime value is the number of days
> that have passed since 12/30/1899. The fractional part of a TDateTime
> value is fraction of a 24 hour day that has elapsed.
>
> Following are some examples of TDateTime values and their
> corresponding dates and times:
>
> 0 * * * 12/30/1899 12:00 am
> 2.75 * *1/1/1900 6:00 pm
> -1.25 * 12/29/1899 6:00 am
> 35065 * 1/1/1996 12:00 am


In the software world, it's generally considered bad form to rely on
the underlying implementation of the date storage. I.e., in general,
it's good not to violate the principle of encapsulation.
Nevertheless, Microsoft has violated that maxim in order to allow
programmers to skirt using something like a DateDiff function when
comparing dates in SQL queries. The chances are almost nil that
Microsoft is going to change the underlying representation of a date
value during this century, but purists would recommend not taking
advantage of the existing internal floating-point representation. I
generally use comparison functions that expect date formats when
comparing dates, but I'm one of those purists I mentioned :-). Even
operator overloading brings up the same issues. The floating point
precision, though, is not really an issue at all when simply comparing
dates, even when comparing to the second (about 0.00001157 of a day).
Mathematically, this is because a conversion to floating-point forms a
partially ordered set (poset) where the corresponding values are
isomorphic to the poset of date/time values (i.e., they maintain the
same relative order as the original date/time values even if the
conversion to number of days plus fraction of a day is not quite
exact). I recommend using the date format for dates and using date
comparisons, ignoring the internal representation. Even if Microsoft
decides to change the internal representation of dates, they will be
responsible for updating any date comparison functions at the same
time, and no changes to your code should be required. Of course, you
are free to determine your own risk comfort level and relaxed degree
of pedantry if adherence to conventional standards of programming is
too onerous in this situation.

James A. Fortune
(E-Mail Removed)
 
Reply With Quote
 
Ulrik Magnusson
Guest
Posts: n/a
 
      10th May 2011
> I need a way to have a
>
> public List<double> XValues = new List<double>();
>
> which also can hold DateTime values.


Why do you need that? Maybe there is some other way to solve your
problem?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a DateTime() to a Double?! chris-s@mailcity.com Microsoft Dot NET Compact Framework 1 23rd Mar 2007 05:48 PM
Byte Array from DateTime Array Daniel Microsoft Dot NET Framework 4 27th Dec 2005 05:24 PM
How many can String Array Hold? Michael Barrido Microsoft Dot NET 2 14th Dec 2005 10:35 AM
treeview node tag hold array? RB Smissaert Microsoft Excel Programming 5 27th Jun 2005 12:32 AM
Howto convert a byte array to double array. kevinniu Microsoft C# .NET 5 19th Jul 2004 09:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.