How to save dates in UK format in CSV?

I save a file as CSV after loading an Excel file. In the Excel file is a date. In the CSV I want the date to be in UK format regardless of the format in the Excel. I’m doing this but it doesn’t work.

var saveOptions = new CsvSaveOptions('\t');
saveOptions.FormatProvider = CultureInfo.GetCultureInfo("en-GB").DateTimeFormat;
workbook.Save(uploadedFileFullPathWithoutExtension + ".txt", saveOptions);

What is the right way to do this?

Hi,

Try this:

var culture = new CultureInfo("en-GB");
culture.DateTimeFormat.ShortDatePattern = "dd MMMM yyyy";
culture.DateTimeFormat.LongTimePattern = "";

var saveOptions = new CsvSaveOptions(CsvType.TabDelimited);
saveOptions.FormatProvider = culture;

Or if the date values are already formatted in the Excel file, then use this:

var saveOptions = new CsvSaveOptions(CsvType.TabDelimited);
saveOptions.UseFormattedValues = true;

Does this solve your issue?

Regards,
Mario

That’s done it. Thanks.