Solved

C# valid date entry

Posted on 2008-10-06
5
565 Views
Last Modified: 2013-12-17
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
Comment
Question by:dotnet0824
  • 2
  • 2
5 Comments
 
LVL 14

Assisted Solution

by:Binuth
Binuth earned 25 total points
Comment Utility
june has only 30 days
0
 
LVL 14

Expert Comment

by:Binuth
Comment Utility
:)
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 75 total points
Comment Utility
to avoid problems with regional settings in different machines, I suggest to use ParseExact:

DateTime.ParseExact(sDate, "d", CultureInfo.InvariantCultureInfo);
0
 
LVL 13

Assisted Solution

by:crazyman
crazyman earned 25 total points
Comment Utility
Lose the try catch and use DateTime.TryParseExact
0
 
LVL 13

Expert Comment

by:crazyman
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now