pdurbha
asked on
Validating date in MMDDYYYY format in C#
Hi,
I am writing a small piece of code that validates a given date against the MMDDYYYY format
Here is my code:
//Validate string date with string date_format MMDDYYYY
public bool validate_datet(string date, string date_format)
{
try
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.LongDatePattern = date_format;
DateTime dt = DateTime.ParseExact(date,d ate_format ,dtfi);
}
catch(Exception)
{
return false;
}
return true;
}
This function returns false even when I pass in a valid date in the MMDDYYYY format such as 06251966. Could anybody tell me what it is that I am doing wrong here..anybody........
Thanks
Praveen
I am writing a small piece of code that validates a given date against the MMDDYYYY format
Here is my code:
//Validate string date with string date_format MMDDYYYY
public bool validate_datet(string date, string date_format)
{
try
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.LongDatePattern = date_format;
DateTime dt = DateTime.ParseExact(date,d
}
catch(Exception)
{
return false;
}
return true;
}
This function returns false even when I pass in a valid date in the MMDDYYYY format such as 06251966. Could anybody tell me what it is that I am doing wrong here..anybody........
Thanks
Praveen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the exact string you are using for the date_format string?
Cheers!
Wint