how to validate a date type
is there a isdate() function in c#
or do i write my own
DaveP
Peter Duniho - 15 Sep 2007 23:04 GMT
> how to validate a date type
> is there a isdate() function in c#
> or do i write my own
What date type? DateTime? A DateTime instance is always a valid date
and time, though it may fall outside of some range you require.
Or do you mean you want to validate a string to verify it represents an
actual date? You could use DateTime.TryParse() to do that, though of
course there are a wide variety of strings that a human could recognize
as a date but which would fail to be parsed. Still, using TryParse()
should give you results useful in a computer program. :)
Pete
Arne Vajhøj - 15 Sep 2007 23:05 GMT
> how to validate a date type
> is there a isdate() function in c#
> or do i write my own
What are you looking for ?
A DateTime type is a DateTime type.
Are you looking to test whether a string contains
a valid date according to either standard formats
or a custom format ?
If that is the case try look at DateTime Parse and
ParseExact methods (or TryParse and TryParseExact).
Arne
DaveP - 15 Sep 2007 23:57 GMT
thats what i used is datetime.parse()
so much in .net....wasn't sure if there was a function out there somewhere
Thank you much
DaveP
>> how to validate a date type
>> is there a isdate() function in c#
[quoted text clipped - 12 lines]
>
> Arne
Arne Vajhøj - 16 Sep 2007 22:10 GMT
> thats what i used is datetime.parse()
> so much in .net....wasn't sure if there was a function out there somewhere
If you use a non standard format then you may need the Exact variants.
Arne