Convert a DateTime to byte[]

F

Fabio

Hi all!

A simple question: I need to convert a DateTime var to a byte[] (or to a
Int64).

How?

Thanks!
 
L

Leon Friesema

Hi all!

A simple question: I need to convert a DateTime var to a byte[] (or to a
Int64).

How?

Thanks!

datetime.ToOaDate() returns an int, maybe that helps?

greetz,
Leon
 
M

Marc Gravell

no - it returns a double; if you wanted to go down this route, .Ticks might
be a reasonable choice...

Marc
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

byte[] b = BitConverter.GetBytes( theDateTime.Ticks);
 
F

Fabio

byte[] b = BitConverter.GetBytes( theDateTime.Ticks);

Thanks to all, this is the right way in, and this the way out:

DateTime d = DateTime.FromBinary(BitConverter.ToInt64(b, 0))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top