Search code examples
asp.net-mvcdatetimefilehelpers

ASP.net FileHelpers failed to convert string to datetime


I work on this issue since almost 2 days. Here is the error message:

FileHelpers.ConvertException: 'Error Converting '8/8/2018 8:48:52 AM' to type: 'DateTime'. There are less chars in the Input String than in the Format string: 'M/d/yyyy hh:mm:ss tt''

I tried a lot of things and it does not work. Tried 'M/d/yyyy h:mm:ss tt'

Tried to put directly in the class like this:

[FieldConverter(ConverterKind.Date, "M/dd/yyyy hh:mm:ss tt")]

Tried almost all possible date formats I could find on here and on google.

Im strugelling with this since almost 2 days.

Please help!

Print screen running step by step with value

Thank you,


Solution

  • DateTime date1 = new DateTime(2008, 4, 10, 6, 30, 0);
    

    the "U" displays Thursday, April 10, 2008 1:30:00 PM from this code

    Console.WriteLine(date1.ToString("U", 
                  CultureInfo.CreateSpecificCulture("en-US")));
    

    You can check all the supported format strings MSDN

    and try this :

        [FieldConverter(ConverterKind.Date, "ddMMyyyy" )]