473,569 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24447
On Wed, 1 Mar 2006 11:44:57 +0100, "Fabio" <zn*******@virg ilio.it>
wrote:
Hi all!

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

How?

Thanks!


datetime.ToOaDa te() 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.Ti cks
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*******@virg ilio.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.Ge tBytes( theDateTime.Tic ks);

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Fabio" <zn*******@virg ilio.it> wrote in message
news:ey******** *****@TK2MSFTNG P09.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.mach in AT dot.state.fl.us > ha
scritto nel messaggio news:%
byte[] b = BitConverter.Ge tBytes( theDateTime.Tic ks);


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

DateTime d = DateTime.FromBi nary(BitConvert er.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
2726
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 recent call last): File "MainFrame.py", line 26, in ? File "Notebook.pyo", line 125, in ? File "NotebookPage_Activities.pyo", line 7, in ?
8
3830
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), GetType(Int32), GetType(Int64), GetType(Single), _ GetType(Double), GetType(Decimal), GetType
2
29482
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
3
14954
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 byte array? Thanks
5
18702
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
3772
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 List<RoleData> GetRoles() { return GetRoles(null, false); }
0
6870
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 since this is the first time, i am working with databases and not really much of an expert. How can I rectify it? One thing more...... Should I be...
3
10368
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 the date. I am trying to convert that to a C# DateTime datatype, but I can't seem to find any documentation on how to do that. Has anyone done...
7
16633
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 returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.