Search code examples
c#vb.netvisual-studio-2010filehelpers

FileHelpers Csv reader - Failing to convert dd-mmm-yyyy DateTime Format


"NIFTY","13-Jun-2012","28-Jun-2012","7100.00"

As one can notice that the Date format of above csv sample is - dd-mmm-yyyy

but Date time format of File helper( may be, Default one ) is - dd-mm-yyyy

while trying to convert csv file im getting following error .

Error Converting '06-Jun-2012' to type: 'DateTime'.  There are more chars in the Input String than in the Format string: 'ddMMyyyy'

Is this possible to convert ,using filehelper, from 06-JUN-2012 to 13-06-2012 . ??

Here is my mDate class used for File helper (v 2.9.16 )

    [FieldTrim(TrimMode.Both)]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    private DateTime mDate;

Solution

  • You must use a converter:

    [FieldTrim(TrimMode.Both)]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    [FieldConverter(ConverterKind.Date, "dd-MMM-yyyy" )] 
    private DateTime mDate;
    

    More options:

    http://www.filehelpers.net/mustread/