• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

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;
        }
0
dotnet0824
Asked:
dotnet0824
  • 2
  • 2
3 Solutions
 
BinuthCommented:
june has only 30 days
0
 
BinuthCommented:
:)
0
 
Jaime OlivaresSoftware ArchitectCommented:
to avoid problems with regional settings in different machines, I suggest to use ParseExact:

DateTime.ParseExact(sDate, "d", CultureInfo.InvariantCultureInfo);
0
 
crazymanCommented:
Lose the try catch and use DateTime.TryParseExact
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now