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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Mar 31, 2009, 7:54 AM EDT
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:
Nipun TomarRank #90 · 23K reputationPosted Mar 31, 2009, 6:38 AM EDT
///
/// 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);
}
waqar laghari62 reputationPosted Mar 31, 2009, 9:04 PM EDT
Thanks you very much you both.. My problem is solved..
Best regards
Waqar Hussain Laghari