[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# valid date entry

Posted on 2008-10-06
5
Medium Priority
?
597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Assisted Solution

by:Binuth
Binuth earned 100 total points
ID: 22648996
june has only 30 days
0
 
LVL 14

Expert Comment

by:Binuth
ID: 22648999
:)
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 300 total points
ID: 22649134
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 100 total points
ID: 22649144
Lose the try catch and use DateTime.TryParseExact
0
 
LVL 13

Expert Comment

by:crazyman
ID: 22649157
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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:…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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