Dear Brother's
I want to create function which returns that date is valid or not.. do you have any idea that how can i create that type of function; Thanks in advance..
Best regards
Waqar Hussain Laghari
Dear Brother's
I want to create function which returns that date is valid or not.. do you have any idea that how can i create that type of function; Thanks in advance..
Best regards
Waqar Hussain Laghari
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Mar 31, 2009, 11:54 AM
try this for validation of a range
DateTime dt;
if (DateTime.TryParse(strDateTime, out dt))
{
DateTime minDateTime = new DateTime(1900, 1, 1);
DateTime maxDateTime = new DateTime(2079, 6, 7); //the day is 7 because of the requirement for the hour to be 23:59:59
if (DateTime.Compare(dt, minDateTime) > 0 && DateTime.Compare(dt, maxDateTime) < 0)
{
//we are in the range
}
}
else
{
//the datetime is not valid
}
or you also can use this:
waqar laghariPosted Apr 1, 2009, 1:04 AM
Thanks you very much you both.. My problem is solved..
Best regards
Waqar Hussain Laghari
Nipun TomarPosted Mar 31, 2009, 10:38 AM
///
/// function.
///
/// The date to validate
///
public static bool ValidateDate(string date)
{
//Dates can be entered in a couple of different formats:
//1. 2008-02-04
//2. 02-04-2008
//3. April 2 2008
//4. April 2, 2008
//5. Apr 2, 2008
//6. 02-APR-2008
//7. 2-APR-08
//It can be done with regular expressions, but DateTime.Parse(string date) method can be used to validate the date.
DateTime dateParsed = new DateTime();
return DateTime.TryParse(date, out dateParsed);
}