473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

string into DateTime?

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.

Aug 29 '07 #1
3 1325
RB
Yin99 wrote:
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.
I think the following code will work:

Dim d As DateTime
d = Date.Parse("8/2/2007 12:00:00 AM")

Cheers,

RB.
Aug 29 '07 #2
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
"Yin99" <ws@ziowave.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
>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.

Aug 29 '07 #3
Yin99 wrote:
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.
Try out DateTime.ParseExact(...)
http://msdn2.microsoft.com/en-us/library/w2sa9yss.aspx

HTH,
Petar Atanasov
http://a-wake.net
Aug 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
2
by: Sterling Ledet | last post by:
I am trying to create a web service that takes a string from my web server in the following format: Mon, 6 Oct 2003 18:39:47 UTC and put's in a datetime so it can then be reformatted in C# as...
38
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
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
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.