473,326 Members | 2,113 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,326 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 3493
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
7
by: Nicolay Korslund | last post by:
Hi! I'm having a little trouble with the typecast operator, can anybody help me with the rules for when the this operator is invoked? In the class 'Test' in the code below, the typecast operator...
2
by: Arun Prasath | last post by:
Hi all, I have the following question regd pointer typecasting. Is the following type of pointer typecasting valid? #define ALLOC(type,num) ((type *)malloc(sizeof(type)*num)) /*begin...
63
by: andynaik | last post by:
Hi, Whenever we type in this code int main() { printf("%f",10); } we get an error. We can remove that by using #pragma directive t direct that to the 8087. Even after that the output is...
11
by: Vinod Patel | last post by:
I have a piece of code : - void *data; ...... /* data initialized */ ...... struct known_struct *var = (struct known_struct*) data; /*typecasting*/ How is this different from simple...
3
by: jdm | last post by:
In the sample code for the SortedList class, I see the use of a string typecasting macro consisting of a single letter "S". i.e.: Sortedlist->Add(S"Keyval one", S"Item one"); Now I have...
7
by: Raghu | last post by:
Hello All, I need some help regarding overloading operation. Is there any way to overload typecasting? I mean if i have a piece of code as below. int a = 2: float b; b = (float)a;
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.