7
votes

I'm using Excel 2010 or Excel 2007 to import CSV file with date/time information. The time stamp in my CSV file have the following format: yyyy-mm-dd hh:mm:ss. (ex: 2015-07-17 12:34:56)

My problem is that Excel seems to auto-detect that the field is a date/time and it is removing the second. Therefore it shows my data as: "2015-07-17 12:34" without the second. Then, when I save my file again in CSV the second are discarded and not present in the CSV anymore !

I find it very time consuming to change the custom cells format of all my files from "yyyy-mm-dd hh:mm" to "yyyy-mm-dd hh:mm:ss".

Is there a way to change the default date/time format in Excel setting or Windows registry?

What is the best (correct) way to force Excel to keep the second when I open and save a CSV file with data/time information in it.

Thanks, ssinfod

3

3 Answers

6
votes

in 'format Cells -> custom' write

yyyy-mm-dd h:mm:ss;@ 

in the Type box

3
votes

It is completely depend on your system date and time format:

  1. Go to Control Panel,
  2. Click on "Region and Language",
  3. Click on "change date, time and number format"
  4. Set "short date", "long date", "short time" and "long time".
0
votes

If you open a CSV file, the seconds are not dropped, they are hidden by the default:

enter image description here

If double-clicked will result in:

enter image description here

If you then save the Excel as CSV, the seconds will be dropped. To save these seconds, you must reformat the cells as:

yyyy-mm-dd hh:mm:ss

before doing the SaveAs