PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms How to check if a string is in a valid DateTime format?

Reply

How to check if a string is in a valid DateTime format?

 
Thread Tools Rate Thread
Old 10-02-2006, 05:29 PM   #1
=?Utf-8?B?QW5kcmV3?=
Guest
 
Posts: n/a
Default How to check if a string is in a valid DateTime format?


Hello, guys,

what is the easiest way to check if a string is in a valid DateTime format
or not in C#.net?

Thanks.
  Reply With Quote
Old 10-02-2006, 06:28 PM   #2
Sonu Kapoor
Guest
 
Posts: n/a
Default Re: How to check if a string is in a valid DateTime fo...

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
  Reply With Quote
Old 10-02-2006, 06:59 PM   #3
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: How to check if a string is in a valid DateTime format?

"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/>

  Reply With Quote
Old 13-02-2006, 07:31 PM   #4
Stoitcho Goutsev \(100\)
Guest
 
Posts: n/a
Default Re: How to check if a string is in a valid DateTime format?

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.



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off