Convert DateTime to Byte Array?

D

David

I need to covert DateTime Variables into a byte array but all of the
conversion methods do not appear to handle the DateTime type. Is
there a generic way to convert any property or object into a byte
array?

Thanks
 
J

Jon Skeet [C# MVP]

David said:
I need to covert DateTime Variables into a byte array but all of the
conversion methods do not appear to handle the DateTime type. Is
there a generic way to convert any property or object into a byte
array?

Well, there's serialization - but for a DateTime, the easiest thing
would be to use the Ticks property to convert it to a long, and then
convert that into a byte array.
 
C

Cor Ligthert

David,

Because that the datetime is a value, that exist as ticks in the format
long, has it not such much sense to place that in a byteArray. Probably you
want a byte array of a ToString converted format. However that is than
depending from the way as you want it in that byte array.

I hope this helps

Cor
 
D

David

I never considered ticks! I tried a string, but when you convert
back, you loose the time portion!

Thanks
 

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