473,411 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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 24405
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: F. GEIGER | last post by:
py2exe and datetime -> No module named datetime I've begun to use the stdlib module datetime instead of my home brewn classes. Since then a py2exe app doesn't run anymore: Traceback (most...
8
by: Sachi | last post by:
Hi, Can anyone convert for me this Vb.bet code into C#? I am trying to convert example a sample from MSDN article. Static types() As Type = {GetType(String), GetType(Byte), _ GetType(Int16),...
2
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
3
by: David | last post by:
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...
5
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
0
by: weird0 | last post by:
Here is the code for executing stored procedure ExecuteSP() , and object that sets all its parameters in other functions and the stored procedure. I think it has something to do with db datatypes...
3
by: Burdzy | last post by:
Hi, I am working on writing a .zip file class based on the PKWare Specifications, and in the .zip format, they save the modified time of the file in 2 pieces: 1. 2 bytes for the time 2. 2 bytes for...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.