469,286 Members | 2,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Convert a DateTime to byte[]

Hi all!

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

How?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net
Mar 1 '06 #1
5 22598
On Wed, 1 Mar 2006 11:44:57 +0100, "Fabio" <zn*******@virgilio.it>
wrote:
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
Mar 1 '06 #2
no - it returns a double; if you wanted to go down this route, .Ticks might
be a reasonable choice...

Marc
Mar 1 '06 #3
Yeah, none of the ConvertTo functions are implemented for DateTime. According to Microsoft they all
throw exceptions:
http://msdn.microsoft.com/library/de...nt64Topic4.asp
http://msdn2.microsoft.com/en-us/library/hx1xzhwe.aspx

DateTime.Now.Ticks
should give you the int64 version of the DateTime

---Tome
http://www.pcdotcom.com
On Wed, 1 Mar 2006 11:44:57 +0100, "Fabio" <zn*******@virgilio.it> wrote:
Hi all!

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

How?

Thanks!

Mar 1 '06 #4
Hi,

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

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Fabio" <zn*******@virgilio.it> wrote in message
news:ey*************@TK2MSFTNGP09.phx.gbl...
Hi all!

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

How?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net

Mar 1 '06 #5
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> ha
scritto nel messaggio news:%
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))

--

Free .Net Reporting Tool - http://www.neodatatype.net
Mar 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Sachi | last post: by
2 posts views Thread by jiangyh | last post: by
3 posts views Thread by David | last post: by
5 posts views Thread by simon | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.