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 / .NET Framework / New Users / March 2004

Tip: Looking for answers? Try searching our database.

datetime parsing problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jai hanuman - 30 Mar 2004 20:59 GMT
this fails.
string sdt="20040330 930";

string[] fmts ={"yyyyMMdd Hmm"};

DateTime date = DateTime.ParseExact(sdt, fmts,

DateTimeFormatInfo.InvariantInfo,
DateTimeStyles.AllowLeadingWhite|DateTimeStyles.AllowTrailingWhite);

any workarounds? urgent, please!!!
TIA
Jochen Kalmbach - 30 Mar 2004 21:17 GMT
> string sdt="20040330 930";
>
> string[] fmts ={"yyyyMMdd Hmm"};
>
> any workarounds? urgent, please!!!

Why not use an regular expression !?

^(\d\d\d\d)(\d\d\)(\d\d)\s+(\d)(\d\d)$

Now you have
Match.Groups[1] = yyyy
Match.Groups[2] = MM
Match.Groups[3] = dd
Match.Groups[4] = H
Match.Groups[5] = mm

Signature

Greetings
 Jochen

  Do you need a memory-leak finder ?
  http://www.codeproject.com/tools/leakfinder.asp
 
  Do you need daily reports from your server?
  http://sourceforge.net/projects/srvreport/

Jochen Kalmbach - 30 Mar 2004 21:30 GMT
>> string sdt="20040330 930";
>>
[quoted text clipped - 5 lines]
>
> ^(\d\d\d\d)(\d\d\)(\d\d)\s+(\d)(\d\d)$

Or even better:
^(\d\d\d\d)(\d\d\)(\d\d)\s+(\d?\d)(\d\d)$

So it will also match HH

Signature

Greetings
 Jochen

  Do you need a memory-leak finder ?
  http://www.codeproject.com/tools/leakfinder.asp
 
  Do you need daily reports from your server?
  http://sourceforge.net/projects/srvreport/

Jon Skeet [C# MVP] - 30 Mar 2004 21:43 GMT
> this fails.
> string sdt="20040330 930";
[quoted text clipped - 7 lines]
>
> any workarounds? urgent, please!!!

The problem (I believe) is that it's greedily taking the hours (as 93).
If you separate the hours from the minutes, or use a 24 hour format, it
should be okay. Is that a possible solution for you?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Katy King - 31 Mar 2004 01:33 GMT
> > this fails.
> > string sdt="20040330 930";
[quoted text clipped - 7 lines]
> >
> > any workarounds? urgent, please!!!

> The problem (I believe) is that it's greedily taking the hours (as 93).
> If you separate the hours from the minutes, or use a 24 hour format, it
> should be okay. Is that a possible solution for you?

Indeed.  Either of the suggestions above (either ParseExact("20040330
0930", "yyyyMMdd Hmm")
or ParseExact("20040330 9 30", "yyyyMMdd H mm")) should succeed.

I have filed a bug on the issue.

Katy King
jai hanuman - 31 Mar 2004 21:33 GMT
> > this fails.
> > string sdt="20040330 930";
[quoted text clipped - 11 lines]
> If you separate the hours from the minutes, or use a 24 hour format, it
> should be okay. Is that a possible solution for you?

thanks, i had to hack it and add the 0 before the hour before parsing it.

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.