I have the string "8/2/2007 12:00:00 AM"
I'd like to get this in DateTime variable so I can manipulate (e.g.
use TimeSpan to find difference). However, when I look at the
DateTime constructors, everything seems to be int, long, etc.
So my question is, what would be the easiest way to get this into
DateTime? Seems like a long way would be to split at the "/", parse
out, use int.Parse, etc (brute force). But I was wondering if there
was a quick and cleaver way to do this in minimal lines of code?
Thanks- Yin
background info: i'm using DateTimePicker control and reading the
value which returns a string in format above. I have two
DateTimePickers and need to know the number of months between the
value in the first DateTimePicker and the second DateTimePicker.
David Wier - 29 Aug 2007 15:52 GMT
if it's truely a DateTime variable, all DateTime members should be available
to you.
could you show us your code?
David Wier
http://aspnet101.com
http://iWritePro.com
>I have the string "8/2/2007 12:00:00 AM"
>
[quoted text clipped - 13 lines]
> DateTimePickers and need to know the number of months between the
> value in the first DateTimePicker and the second DateTimePicker.
RB - 29 Aug 2007 15:53 GMT
> I have the string "8/2/2007 12:00:00 AM"
>
[quoted text clipped - 13 lines]
> DateTimePickers and need to know the number of months between the
> value in the first DateTimePicker and the second DateTimePicker.
I think the following code will work:
Dim d As DateTime
d = Date.Parse("8/2/2007 12:00:00 AM")
Cheers,
RB.
Petar Atanasov - 29 Aug 2007 15:58 GMT
> I have the string "8/2/2007 12:00:00 AM"
>
[quoted text clipped - 13 lines]
> DateTimePickers and need to know the number of months between the
> value in the first DateTimePicker and the second DateTimePicker.
Try out DateTime.ParseExact(...)
http://msdn2.microsoft.com/en-us/library/w2sa9yss.aspx
HTH,
Petar Atanasov
http://a-wake.net