Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
like image 233
panindra Avatar asked Dec 15 '22 19:12

panindra


1 Answers

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/

like image 173
Marcos Meli Avatar answered Dec 28 '22 23:12

Marcos Meli