PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
How to check if a string is in a valid DateTime format?
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
How to check if a string is in a valid DateTime format?
![]() |
How to check if a string is in a valid DateTime format? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello, guys,
what is the easiest way to check if a string is in a valid DateTime format or not in C#.net? Thanks. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Use Convert.ToDateTime(yourstring) inside a try/catch. If it comes inside the catch, then the passed string is probably invalid.
Sonu Kapoor [MVP] --- Posted via www.DotNetSlackers.com |
|
|
|
#3 |
|
Guest
Posts: n/a
|
"Andrew" <Andrew@discussions.microsoft.com> schrieb:
> what is the easiest way to check if a string is in a valid DateTime format > or not in C#.net? 'DateTime.Parse'/'DateTime.ParseExact' + 'try...catch' in .NET 1.*, 'DateTime.TryParse' in .NET 2.0. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Andrew,
I believe that would be DateTime.TryParse (if you want just to check)or DateTime.Parse. -- HTH Stoitcho Goutsev (100) "Andrew" <Andrew@discussions.microsoft.com> wrote in message news:F78BFCB3-6CBB-4E7E-ACB3-4D44F8B13436@microsoft.com... > Hello, guys, > > what is the easiest way to check if a string is in a valid DateTime format > or not in C#.net? > > Thanks. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

