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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:55:13+00:00 2026-05-18T01:55:13+00:00

I try to read a csv file. my fifth record contans a date: 03/11/2008

  • 0

I try to read a csv file.
my fifth record contans a date: 03/11/2008

This is a piece of my code:

    [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")]
    public DateTime datum_5;

My code crashs on this:

Result[] results= (Result[])engine.ReadFile(@"..\Data\expo.txt");

And with this exception:
Line: 1. Column: 41. Field: datum_5. Error Converting ’03/11/2008′ to type: ‘DateTime’. Using the format: ‘dd/MM/yyyy’

When i do this:

[FieldConverter(typeof(ConvertDate))]

        public DateTime datum_5;

with this:

internal class ConvertDate : ConverterBase
   {

       /// <summary>
       /// different forms for date separator : . or / or space
       /// </summary>
       /// <param name="from">the string format of date - first the day</param>
       /// <returns></returns>

       public override object StringToField(string from)
       {
           DateTime dt;

           if (DateTime.TryParseExact(from, "dd.MM.yyyy", null, DateTimeStyles.None, out dt))
               return dt;

           if (DateTime.TryParseExact(from, "dd/MM/yyyy", null, DateTimeStyles.None, out dt))
               return dt;

           if (DateTime.TryParseExact(from, "dd MM yyyy", null, DateTimeStyles.None, out dt))
               return dt;

           throw new ArgumentException("can not make a date from " + from, "from");

       }
   }

I got this exception: can not make a date from 03/11/2008
Parameternaam: from

What am i doing wrong?

  • 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-18T01:55:14+00:00Added an answer on May 18, 2026 at 1:55 am

    The reason it’s failing is that / in a custom date format string is a culture-specific DateSeparator as described in MSDN.

    You are specifying null for the IFormatProvider argument, so it’s using the current culture, which presumably has a date separator other than /.

    The best solution is to explicitly specify CultureInfo.InvariantCulture (second version below). Escaping the ‘/’ in your custom date format string so that it is treated as a literal slash rather than a DateSeparator will also work (first version below).

    // Set current culture to a culture that uses "." as DateSeparator
    Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
    // This will work - escaping means it uses a literal / as the separator
    DateTime.TryParseExact(s, @"dd\/MM\/yyyy", null, DateTimeStyles.None, out result);
    
    // This is better - Culture.InvariantCulture uses / for the DateTimeFormatInfo.DateSeparator
    // and you clearly express the intent to use the invariant culture
    DateTime.TryParseExact(s, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out result);
    
    // This will fail - / means use DateTimeFormatInfo.DateSeparator which is "." in the de-DE culture
    DateTime.TryParseExact(s, "dd/MM/yyyy", null, DateTimeStyles.None, out result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to read file /proc/'pid'/status, using c program. The code is as follows,
I have a 3GB CSV file that I try to read with python, I
I have this code to read a CVS file. It reads each line, devides
I'm trying to read a CSV file with a date format 06/01/05 (month/date/year) into
I'm using opencsv in my application but whenever I try to read my csv
In the following code, I try to read data from a plist: -(void)readPreferences {
I try to read a CSV and echo the content. But the content displays
I have a small script we're using to read in a CSV file containing
To simplify, I'm trying to read the content of a CSV-file using the ifstream
So far I have: //read in data from CSV file and separate it into

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.