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 8138723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:35:12+00:00 2026-06-06T11:35:12+00:00

I am unable to convert strings to date with throwing exceptions of not proper

  • 0

I am unable to convert strings to date with throwing exceptions of not proper format:

here are the patterens:

    DD-MM-YYYY
    MM-DD-YYYY
    YYYY-DD-MM
    YYYY-MM-DD
    YYYYDDMM
    YYYYMMDD

formats are coming from dropdown list and here is what I tried different method but still its throwing exceptions:

 strCurrentFormat = rcboDateFormat.SelectedValue.ToString();

                 DateTime db = DateTime.ParseExact(strOldDate, "DD-MM-YYYY", CultureInfo.InvariantCulture);

                 //DateTime loadedDate = DateTime.ParseExact(strOldDate, strCurrentFormat, null);

I have solved this problem before by taking string, split them and move the year and month and day around to proper format but that would take long time, if anyone knows an easier way it would be a tremendous help.

  • 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-06-06T11:35:14+00:00Added an answer on June 6, 2026 at 11:35 am

    Two things:

    First – use the correct format strings. D and Y are not known format specifiers. d and y are.

    Second – you can put your formats into a string array and use the ParseExact overload that takes that list of formats.

    string[] formats = new string[] 
       {"dd-MM-yyyy",
        "MM-dd-yyyy",
        "yyyy-dd-MM",
        "yyyy-MM-dd",
        "yyyyddMM",
        "yyyyMMdd"};
    
    DateTime db = DateTime.ParseExact(strOldDate, 
                                      formats, 
                                      CultureInfo.InvariantCulture,
                                      DateTimeStyles.None);
    

    The formats will be attempted in order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the Unable to convert MySQL date/time value to System.DateTime error because
can someboody please help me convert these strings/ints into a usable font thing? it
I am unable to convert JSON string to .net object in asp.net. I am
I have a code snippet in C# but unable to convert to VB.NET. I
I have to convert a string into binary using UTF-8, but i am unable
currentDateTime = [NSDate date]; dateFormatter = [[NSDateFormatter alloc]init] ; [dateFormatter setDateFormat:@yyyy-mm-dd hh:mm]; // 1999-12-12
On some occasions data() is converting my dates incorrectly. My date formats look like
I am being passed lists of strings that I would like to convert to
I am trying to convert a string into Date using Derived column and I
Unable to cast object type System.Collections.Generic.List 1[NorthwindMVC3.Models.Product] to the type ofSystem.Collections.Generic.IEnumerator 1[NorthwindMVC3.Models.Product].\ public IEnumerator<Product>

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.