CsvHelper changing how dates and times are output

With newer version (12.1.2) of CsvHelper, it can be achieved by using TypeConverterOptionsCache

var options = new TypeConverterOptions { Formats = new[] { "MM/dd/yyyy" } };
csvWriter.Context.TypeConverterOptionsCache.AddOptions<DateTime>(options);

Output date

08/24/1991

Version 20 moved TypeConverterOptionsCache from Configuration to Context. So the above becomes

var options = new TypeConverterOptions { Formats = new[] { "MM/dd/yyyy" } };
csvWriter.Context.TypeConverterOptionsCache.AddOptions<DateTime>(options);
csvWriter.Context.TypeConverterOptionsCache.AddOptions<DateTime?>(options);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)