I am trying to get the actual bytes from memory that the current date and time is stored in. Getting the bytes will compress the data since I will be saving it and encrypt it to the average user. I believe that there are 8 bytes that make up a data and they are stored in a double precision floating point number. I tried this

Dim D as doubl

D = cdbl(now

It just underlined now and said there was an invalid conversion. With the number value of the date variable, I could at least convert it back to the byte format myself. However, it would save a lot of cpu if the bytes could be read directly. My ultimate goal is the data in a byte array so it can be easily saved. I'm not sure how to get the actual bytes from memory though.

Are there any other common ways of compressing dates? Thanks for the help.

Re: Date Question by Chris

Chris
Fri May 28 20:50:43 CDT 2004

Use the BitConverter's GetBytes method.

-Chris


"Jonathan" <anonymous@discussions.microsoft.com> wrote in message
news:BC8A68EB-C3C9-41FB-B94B-4D9A45DADCB6@microsoft.com...
> I am trying to get the actual bytes from memory that the current date and
time is stored in. Getting the bytes will compress the data since I will be
saving it and encrypt it to the average user. I believe that there are 8
bytes that make up a data and they are stored in a double precision floating
point number. I tried this:
>
> Dim D as double
>
> D = cdbl(now)
>
> It just underlined now and said there was an invalid conversion. With the
number value of the date variable, I could at least convert it back to the
byte format myself. However, it would save a lot of cpu if the bytes could
be read directly. My ultimate goal is the data in a byte array so it can be
easily saved. I'm not sure how to get the actual bytes from memory though.
>
> Are there any other common ways of compressing dates? Thanks for the help.



Re: Date Question by anonymous

anonymous
Sat May 29 17:11:02 CDT 2004

Thanks for the reply. I found an example of how to use the bit converter but it doesn't seem to like dates. Here is the code I used

Dim d As Dat
Dim BitArr As System.Arra

d = No
d = BitConverter.GetBytes(d

It highlighter GetBytes and says that the date can't be converted to: long, short, etc. There were several formats that getbytes accepted but date is not one of them. The only useful suggestion it gave was to use the Date.ToOADate method. However, I typed it in and it was not recognized. I also tried just ToOADate(d). I did a google search and only found one result that was for C# and the DateTimePicker control. I am just using a variable, not the control.

Is it possible to convert this VB6 code to .net

Dim Y as doubl

Y = No

Y will now contain a number (since it is a double). The number will be a decimal of the number of days since 1900. With this number I could do my own encryption. I just want to reduce the size as much as possible since there will be thousands of dates saved. The optimal solution would be to just get the bytes right out of memory. Is there a way to trick the compiler and convince it that the date is really a double and use a pointer to get the value of each byte?