Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:00:34+00:00 2026-05-13T19:00:34+00:00

I want to check if a date has a correct format. There is many

  • 0

I want to check if a date has a correct format. There is many possibilities of correct dates like:

  • 02.08.2010
  • 2.8.2010
  • 02.8.2010 02.08
  • 02.August
  • …

I can test each on with code like this:

if (DateTime.TryParse(DateTime.ParseExact(date, "dd.M.", 
                              new CultureInfo("sl-SI")).ToString(), out dt))

But then I can have 40 if statements. Is it possible to check all dates with one if statement or one loop?

Update:

Based on the answers so far, I am testing this code, but I have one more problem. What if I have just 9.2 not 9.2.2010 then this code will not work:

CultureInfo ci = CultureInfo.GetCultureInfo("sl-SI");
string[] fmts = ci.DateTimeFormat.GetAllDateTimePatterns();

if (DateTime.TryParseExact(date, fmts, ci, DateTimeStyles.AssumeLocal, out dt))
{
    DateTime = Convert.ToDateTime(date);
    Check = true;
}

Must I manually add this times or what can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:00:34+00:00Added an answer on May 13, 2026 at 7:00 pm

    You can use something like the following, but be aware that more than one format might be able to parse the same date. For example 10/11/12 can be parsed as yy/MM/dd or MM/dd/yy, which are both valid US date formats. MM/dd/yy is more common, so it appears first in the list and is the one returned by the code below (if you use it with a US culture instead of the culture in the example).

    string testValue = "10.11.12";
    
    DateTime result;
    CultureInfo ci = CultureInfo.GetCultureInfo("sl-SI");
    string[] fmts = ci.DateTimeFormat.GetAllDateTimePatterns();
    Console.WriteLine(String.Join("\r\n", fmts));
    if (DateTime.TryParseExact(testValue, fmts, ci,
       DateTimeStyles.AssumeLocal, out result))
    {
       Console.WriteLine(result.ToLongDateString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field (nonTimeStampDate) that has date like this 2010-03-15 and I want
I want to enforce CHECK constraint on a date range such that all dates
I want to check whether a date is between start date and end date.
I want to check if a given date is more than a month earlier
I want to do a Date Check on a TextBox with a onBlur event.
I have an application that passes in java.util.Date. I want to check whether this
I have a drop down that has the years basically 2011,2010,2009 etc... and there
I'm using the following code to check if a valid date has been typed
Hello how can i determine with a program (c#) if the Bios Date has
@ Gouki Pls check if this is a correct Implementation as there may be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.