471,319 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Typecasting DateTime

I need to put a DateTime variable in a MemoryStream via a StreamWriter.

Is there a way to convert the DateTime object into another data type (UInt64
for exemple?)

Or is there an easy way to put it in my memory stream?

Thank You
Feb 22 '06 #1
6 3435
Michael,

You can use the Convert class . It provides methods Convert.ToInt64 and
Convert.ToDateTime
--
HTH
Stoitcho Goutsev (100)

"Michel Racicot" <mr******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need to put a DateTime variable in a MemoryStream via a StreamWriter.

Is there a way to convert the DateTime object into another data type
(UInt64 for exemple?)

Or is there an easy way to put it in my memory stream?

Thank You

Feb 22 '06 #2

http://blogs.msdn.com/bclteam/archiv...21/136918.aspx

MR> I need to put a DateTime variable in a MemoryStream via a
MR> StreamWriter.
MR>
MR> Is there a way to convert the DateTime object into another data type
MR> (UInt64 for exemple?)
MR>
MR> Or is there an easy way to put it in my memory stream?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Feb 22 '06 #3
Exactly what I was looking for! Thank you!

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...

http://blogs.msdn.com/bclteam/archiv...21/136918.aspx

MR> I need to put a DateTime variable in a MemoryStream via a
MR> StreamWriter.
MR> MR> Is there a way to convert the DateTime object into another data
type
MR> (UInt64 for exemple?)
MR> MR> Or is there an easy way to put it in my memory stream?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Feb 22 '06 #4
I've tried this... And you can't convert a DateTime to Int64 (There is no
implicit conversion between the two types as it is possible in other
language/frameworks such as Delphi's VCL)

"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...
Michael,

You can use the Convert class . It provides methods Convert.ToInt64 and
Convert.ToDateTime
--
HTH
Stoitcho Goutsev (100)

"Michel Racicot" <mr******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need to put a DateTime variable in a MemoryStream via a StreamWriter.

Is there a way to convert the DateTime object into another data type
(UInt64 for exemple?)

Or is there an easy way to put it in my memory stream?

Thank You


Feb 22 '06 #5
Michael,

Yes, you are right. Covert class doesn't work for DateTime. The reason being
is the IConvertibe methods throw InvalidCast exception. However in case
where you use .NET 2.0 the DateTime clas there support methods ToBinary and
FromBinary that converts to *long* and from *long*. Interestingly
IConvertible.ToInt64 still throws the exception.
--
HTH
Stoitcho Goutsev (100)

"Michel Racicot" <mr******@hotmail.com> wrote in message
news:es***************@tk2msftngp13.phx.gbl...
I've tried this... And you can't convert a DateTime to Int64 (There is no
implicit conversion between the two types as it is possible in other
language/frameworks such as Delphi's VCL)

"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...
Michael,

You can use the Convert class . It provides methods Convert.ToInt64 and
Convert.ToDateTime
--
HTH
Stoitcho Goutsev (100)

"Michel Racicot" <mr******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need to put a DateTime variable in a MemoryStream via a StreamWriter.

Is there a way to convert the DateTime object into another data type
(UInt64 for exemple?)

Or is there an easy way to put it in my memory stream?

Thank You



Feb 22 '06 #6
The datetime type works from the Ticks property which is also the parameter
to a constructor of it.
Just write the DateTime.Ticks to the stream and when you pull it out, call
the contructor with that as a param.

HTH

Ciaran
"Michel Racicot" <mr******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need to put a DateTime variable in a MemoryStream via a StreamWriter.

Is there a way to convert the DateTime object into another data type
(UInt64 for exemple?)

Or is there an easy way to put it in my memory stream?

Thank You

Feb 22 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kapil Khosla | last post: by
7 posts views Thread by Nicolay Korslund | last post: by
63 posts views Thread by andynaik | last post: by
11 posts views Thread by Vinod Patel | last post: by
7 posts views Thread by Raghu | last post: by
12 posts views Thread by bwaichu | last post: by

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.