简体   繁体   中英

How to convert a date in Excel to ISO 8601 format

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?

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.

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. Eg with my formatting settings to German:

=TEXT(C2;"jjjjMMtt")

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

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. FYI.

您可以直接跳到核选项:更改计算机的“区域和语言”设置以使用“yyyy-MM-dd”短日期格式。

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)

Sorry for my english.

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.

FWIW,以上都没有在16世纪日期的Excel中为我工作,例如1558年8月26日的26-08-1558。所以为了将其转换为ISO日期,我使用了:

=RIGHT(D2|4)&"-"&MID(D2|4|2)&"-"&LEFT(D2|2)
=DATEVALUE(LEFT(A1;10))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM