C# valid date entry

Function returns false though valid date is entered.

Date Entered : 06/31/2008
 private static bool IsDate(string sDate)
        {
            DateTime dt;
            bool isDate = true;

            try
            {
                dt = DateTime.Parse(sDate);
            }
            catch
            {
                isDate = false;
            }

            return isDate;
        }
dotnet0824Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
to avoid problems with regional settings in different machines, I suggest to use ParseExact:

DateTime.ParseExact(sDate, "d", CultureInfo.InvariantCultureInfo);
0
 
BinuthConnect With a Mentor Commented:
june has only 30 days
0
 
BinuthCommented:
:)
0
 
crazymanConnect With a Mentor Commented:
Lose the try catch and use DateTime.TryParseExact
0
All Courses

From novice to tech pro — start learning today.