61

I am trying to save a date format in YYYY-MM-DD, for example, 2014-09-01 as a CSV file, but the format reverts back to the M/D/YYYY format when I do.

I tried converting the date as a string in Excel, but every time I open up the CSV file, it's back to the M/D/YYYY format. I need the ISO 8601 date format to be saved in a CSV file. How do I go about doing so?

1
  • 11
    Yes, the M/D/Y format is pretty useless - you can't sort by date on it, and violates what we learned in grade 1 - numbers have their most significant digits on the left, least significant on the right (hundred / tens / units, remember). So millennia (i.e. thousands of years) are obviously more significant than hundreds, tens, units of years, then tens of months, units of months, then tens of days, units of days. Dunno why people still use M/D/Y in the 21st century - it should be banned. Commented Sep 11, 2017 at 10:09

8 Answers 8

85

The basic function is:

=TEXT(A1,"yyyy-mm-ddThh:MM:ss") 

Use this to convert your Excel date columns to separate ISO 8601 date columns. Next, copy the ISO 8601 columns onto the originals (paste special: paste values only). Delete the calculated ISO 8601 columns which now have garbage in them because Excel sucks at ISO 8601 dates.

You now have a transformed CSV or TSV or whatnot. Just save as the original format and ignore the stupid Excel whining about it not being its native file format and how you are going to "lose out" somehow by saving as CSV file and try not to think about the hours of your life Microsoft has stolen with that dumb dialog.

Sign up to request clarification or add additional context in comments.

Comments

22

You can set up a cell, example :

Right click on cell > Cell format > Category > Custom > Type > write this :

aaaa-mm-jjThh:mm:ss (french format here) yyyy-mm-ddThh:MM:ss (english format) 

2 Comments

Also, for milliseconds it is: yyyy-mm-ddThh:MM:ss.000
I would prefer to use this method, to keep the time and date alive in Excel (not just a text string), but I can't work out how to add the time zone date eg: 2014-01-01T01:00:00+0800 indicating the Western Australian timezone of +08 hours relative to GMT.
12

As a note of caution for non-English users. It just took me a while to figure out, that the format string is sensitive to your regional settings / locale. E.g. with my formatting settings to German:

=TEXT(C2;"jjjjMMtt") 

(Although the OS and Excel are set to English.)

1 Comment

I think you should use =TEXT(A2;"jjjjMMtt") instead, or you show minutes instead of Months
9

I copied and pasted @Dirk Bester's formula above:

=TEXT(A1,”yyyy-mm-ddThh:MM:ss”) 

but it wouldn't work, Excel 2010 complaining high and low. That is, until I changed the quote marks from some kind of "smart quote" to plain old ASCII 0x22 quote marks:

=TEXT(A1,"yyyy-mm-ddThh:MM:ss") 

And now it works like a charm.

1 Comment

Weird, wonder how those slipped in there. Smart quotes are really dumb.
6

You could just jump straight to the nuclear option: Change your computer’s "Region and Language" settings to use the "yyyy-MM-dd" short date format.

1 Comment

Start out with a csv that has format 21-6-2019. Make sure your regional settings are the same. Doubleclick the CSV to open in Excel (do not use data/from text, that won't work. Don't ask me why). Excel will recognise the dates as dates. Now select each date column and change the format Date to 2019-06-21. Excel 2016.
1

I believe you may well have created the right format in the .csv file.

But that Excel is automatically coercing that into a date value of the format you mention when you open the .csv file. A solution may be to import the .csv file rather than open it, and at step 3 of Get External Data, From Text, ensure that Text is selected for Column data format, where appropriate.

1 Comment

Open the CSV file in notepad to test this theory. Excel is too clever for it's own good some days.
1

FWIW, none of the above worked for me in an Excel with 16th century dates, e.g. 26-08-1558 for the 26th of August 1558. So in order to convert that to an ISO date, I used:

=RIGHT(D2|4)&"-"&MID(D2|4|2)&"-"&LEFT(D2|2) 

Comments

0
=DATEVALUE(LEFT(A1;10)) 

I used that

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.