0
votes

having trouble with date formats in CSV file format(Excel)

I want the date in "YYYY-MM-DD hh:mm " format and I need it in .CSV format.

When reopening the file, the date format gets changed and it looks like "MM-DD-YYYY hh:mm".

Does anyboy know how I can retain my desired date format when saving the file as .CSV?

Thank you!

1
Re-open the file with what? Excel? Then Excel will again try to interpret the date. Open the file with a text editor to see what the underlying data is. - teylyn
csv is flat file and it will not be able to retain any formatting related information. So when you open it again in Excel, then Excel will assign type and display. - shrivallabha.redij

1 Answers

2
votes

Use the format YYYYMMDD in all CSV files, which doesn't convert to date in Excel or you can do one of the below things

  1. Use a Custom format, rather than one of the pre-selected Date formats, the export to CSV will keep your selected format. Otherwise it defaults back to the US format

  2. Place an apostrophe in front of the date and it should export in the correct format. Just found it out for myself, I found this thread searching for an answer.

  3. Change the date and time settings for your computer in the "short date" format under calendar settings. This will change the format for everything yyyy-mm-dd or however you want it to display; but remember it will look like that even for files saved on your computer.