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.
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)
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.)
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.
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.
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, 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)
=DATEVALUE(LEFT(A1;10))
I used that
Related
How can one regularise the dates format for below dates?
I want all below dates in format "22-Feb-17"
NOTE: Please note that I've tried converting the format by going to change format in the main menu section, but it didn't work.
Also tried: right click> Format Cell> Date > selected "22-Feb-17". This also didn't work.
27/04/2017
27/04/2017
27/04/2017
27/04/2017
5-Feb-17
5-Feb-17
5-Mar-17
5-Mar-17
5-Apr-17
5-Apr-17
5-Aug-17
5-Aug-17
22/5/2017
22/05/2017
24/05/2017
Please advise.
Go back to your original csv file, before it was ever opened and saved in Excel.
Then choose to Import the file (exactly where depends on your excel version). The Text import wizard will open and you will be able to specify the proper format of the dates in the csv file (eg. DMY).
Once they are properly imported as dates, you will be able to format the column however you wish.
Although it is definitely best to revert back to source and start again with an appropriate conversion, in case source is not available a formula conversion may serve:
=IF(ISTEXT(A1),DATE(2017,MID(A1,4,2),LEFT(A1,2)),DATE(2017,DAY(A1),MONTH(A1)))
This assumes (i) all dates are 2017 (easy enough to adjust if not) (ii) dates containing forward slashes are correct but in text format (iii) dates containing hyphens have the month and day switched around but are in date format.
I need to separate the date and time for a large list of data in Excel, the format is 12/23 1600 (i.e. 23 December 16:00).
I tried the function =DATE(YEAR(serial_number),MONTH(serial_number),DAY(serial_number)), but it couldn't read that format.
Could you please tell me how to do that without change the format?
This works for me as I see your data
=DATE(YEAR(TODAY()),LEFT(A2,2),MID(A2,4,2))
and
=TIME(INT(MID(A2,FIND(" ",A2)+1,9)/100),MOD(MID(A2,FIND(" ",A2)+1,9)/100,1)*100,0)
If the data is a string, AND IF your windows short date regional format is MDY, then try:
=DATEVALUE(LEFT(A1,FIND(" ",A1)-1))
If the data is a "real" date, formatted to appear as you show, then try:
=INT(A1)
In either case, be sure to format the result as you desire.
If your Windows regional settings are other than MDY, then you can use this more complex formula:
=DATE(YEAR(TODAY()), LEFT(A1,FIND("/",A1)-1),MID(LEFT(A1,FIND(" ",A1)-1),FIND("/",A1)+1,2))
For the time portion, you can try
=TIMEVALUE(REPLACE(RIGHT(A1,4),3,0,":"))
If the above does not work, then provide more information about exactly what is in the cell, your regional format, etc.
When importing data from a text file (csv) into MS Access, I get an error "Type conversion failure" for 1 field. The field has data with date format "yyyy-mm-dd hh:nn:ss" and Access simply refuses to recognise it and places #Num! or simply blank data. The csv file is huge with 8m rows and cannot be opened in Excel to edit the date format. Facing no problems with any other fields.Anyway to avoid this error?
Use the Advanced... button at the field specification step of the import and try these settings:
I don't have the exact date format in the picture above, but it is just to show how to import that specific date.
Date Order should be YMD because in your dates, you have the years coming first, followed by the month and the date.
The date delimiter for your csv will be a dash -, while the time delimiter should be the default colon :. Make sure the 4 digit years checkbox is checked, and I would also check the Leading Zeros in Dates checkbox since your month and dates are in mm and dd formats respectively (i.e. they will begin with 0 if it is a single digit).
If there are problematic dates from your csv now, then this is another problem that won't be easy to tackle. You will maybe have to correct the date manually from the csv before importing it, or import the date as text and then create a new column to manipulate the text dates to date fields (and fix any problematic dates there).
Nothing wrong with the date format, but some records may be empty or have invalid entries.
Or you miss at the import to specify the separators and format for the date field.
If still no luck, link the file and specify text for the field. Then create a select query that uses the linked file as source and use CDate to convert the text date to true date values.
When done, change the query to an append or create table query to import your data.
We're exporting our analytics reports in various formats, among them CSV. For some clients this CSV finds it's way into Excel.
Inside the CSV file one of the columns is a Date, for example
"Start Date","Name"
"07-04-2010", "Maxim"
Excel has trouble parsing this date format, obviously depending on the Locale of the user. Is "07" is the day or the month...
Could you recommend some textual format for a Date field that excel will not have trouble parsing? I'm aiming at the most fail safe option possible. I would settle for some escape sequence that will cause excel to avoid parsing the text in the column altogether.
Thanks for helping,
Maxim.
You have two options. Go with the month as a string and the year as 4 digits, or use ISO formatting: yyyy-mm-dd.
If you format your dates as follows in the csv output, Excel will parse the content exactly as a date (other columns for realism only)
43,somestring,="03/03/2003",anotherval
55,anotherstring,="01/02/2004",finalval
so add ="{date}" and it parses as date!
I'm writing a CSV file. I need to write timestamps that are accurate at least to the second, and preferably to the millisecond. What's the best format for timestamps in a CSV file such that they can be parsed accurately and unambiguously by Excel with minimal user intervention?
For second accuracy, yyyy-MM-dd HH:mm:ss should do the trick.
I believe Excel is not very good with fractions of a second (loses them when interacting with COM object IIRC).
The earlier suggestion to use "yyyy-MM-dd HH:mm:ss" is fine, though I believe Excel has much finer time resolution than that. I find this post rather credible (follow the thread and you'll see lots of arithmetic and experimenting with Excel), and if it's correct, you'll have your milliseconds. You can just tack on decimal places at the end, i.e. "yyyy-mm-dd hh:mm:ss.000".
You should be aware that Excel may not necessarily format the data (without human intervention) in such a way that you will see all of that precision. On my computer at work, when I set up a CSV with "yyyy-mm-dd hh:mm:ss.000" data (by hand using Notepad), I get "mm:ss.0" in the cell and "m/d/yyyy hh:mm:ss AM/PM" in the formula bar.
For maximum information[1] conveyed in the cells without human intervention, you may want to split up your timestamp into a date portion and a time portion, with the time portion only to the second. It looks to me like Excel wants to give you at most three visible "levels" (where fractions of a second are their own level) in any given cell, and you want seven: years, months, days, hours, minutes, seconds, and fractions of a second.
Or, if you don't need the timestamp to be human-readable but you want it to be as accurate as possible, you might prefer just to store a big number (internally, Excel is just using the number of days, including fractional days, since an "epoch" date).
[1]That is, numeric information. If you want to see as much information as possible but don't care about doing calculations with it, you could make up some format which Excel will definitely parse as a string, and thus leave alone; e.g. "yyyymmdd.hhmmss.000".
"yyyy-MM-dd hh:mm:ss.000" format does not work in all locales. For some (at least Danish) "yyyy-MM-dd hh:mm:ss,000" will work better.
I believe if you used the double data type, the re-calculation in Excel would work just fine.
Go to the language settings in the Control Panel, then Format Options, select a locale and see the actual date format for the chosen locale used by Windows by default. Yes, that timestamp format is locale-sensitive. Excel uses those formats when parsing CSV.
Even further, if the locale uses characters beyond ASCII, you'll have to emit CSV in the corresponding pre-Unicode Windows "ANSI" codepage, e.g. CP1251. Excel won't accept UTF-8.
"yyyy-mm-dd hh:mm:ss.000" format does not work in all locales. For
some (at least Danish) "yyyy-mm-dd hh:mm:ss,000" will work better.
as replied by user662894.
I want to add: Don't try to get the microseconds from, say, SQL Server's datetime2 datatype: Excel can't handle more than 3 fractional seconds (i.e. milliseconds).
So "yyyy-mm-dd hh:mm:ss.000000" won't work, and when Excel is fed this kind of string (from the CSV file), it will perform rounding rather than truncation.
This may be fine except when microsecond precision matters, in which case you are better off by NOT triggering an automatic datatype recognition but just keep the string as string...
So, weirdly excel imports a csv date in different ways. And, displays them differently depending on the format used in the csv file. Unfortunately the ISO 8061 format comes in as a string. Which prevents you from possibly reformatting the date yourself.
All the ones the do come in as a date... contain the entire information... but they format differently... if you don't like it you can choose a new format for the column in excel and it will work. (Note: you can tell it came in as a valid date/time as it will right justify... if it comes in as a string it will left justify)
Here are formats I tested:
"yyyy-MM-dd" shows up as a date of course when opened in excel. (also "MM/dd/yyyy" works)
"yyyy-MM-dd HH:mm:ss" default display format is "MM/dd/yyyy HH:mm" (date and time w/out seconds)
"yyyy-MM-dd HH:mm:ss.fff" default display format is "HH:mm:ss" (time only w/ seconds)
As for timezones. I have to store the UTC offset as seconds from UTC that way formulas in Excel/OpenOffice can eventually localize datetimes. I found this to be easier than storing any number that has a 0 in front of it. -0900 didn't parse well in any spreadsheet system and importing it was nearly impossible to train people to do.
Try MM/dd/yyyy hh:mm:ss a format.
Java code to create XML file.
xmlResponse.append("mydate>").append(this.formatDate(resultSet.getTimestamp("date"),
"MM/dd/yyyy hh:mm:ss a")).append("");
public String formatDate(Date date, String format)
{
String dateString = "";
if(null != date)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateString = dateFormat.format(date);
}
return dateString;
}
I wrote my timestamps to the CSV file as yyyy-mm-dd hh:mm:ss.
In Excel 365 I create a blank workbook, go to the Data tab and choose "From Text/CSV.
A dialog opens with a preview, which weirdly leaves the first column of timestamps alone, but shows it is going to convert the second column.
You can either "Load" the data, or "Transform Data", which is what I choose.
Now you're in the "Power Query Editor" and you can massage how Excel will bring the columns in.
In my case I undo any automatic changes it made, and tell it both columns are Data Type "Date/Time" using a little button on the ribbon.
Pressing Close & Load brings it into Excel as a data source that you can sort etc.
Given a csv file with a datetime column in this format: yyyy-mm-dd hh:mm:ss
Excel shows it in this format: dd/mm/yyyy hh:mm
e.g. 2020-05-22 16:40:55 shows as 22/05/2020 16:40
This is evidently determined by the Short date and Short time format selected in Windows; for example, if I change the Short date format in Windows to yyyy-mm-dd, Excel shows 2020-05-22 16:40.
Annoyingly, I can't find any way to make Excel show the seconds automatically (I have to manually format the column in Excel). But if the csv file includes a time column in hh:mm:ss format (e.g. 16:40:55), that's what shows in Excel, including the seconds.
I would guess that ISO-format is a good idea. (Wikipedia article, also with time info)