Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

string into DateTime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yin99 - 29 Aug 2007 15:37 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.