简体   繁体   中英

Different date formats in Excel

I have a csv that contains a list of dates, once imported into Excel they are in 2 different formats. How can I get them all in the same format?

Example:

01/23/2012
01/26/2012
40910
41031

You probably have a BIG issue with your file!

Probably, Excel is recognizing dates as "dd/mm/yyyy" but your data is "mm/dd/yyyy" formatted.

So, your numbers are really dates (just format, as @t.thielemans suggested). But are incorrectly parsed - month and day are switched!

Solution (assuming your dates are on A:A column):

To convert text to date:

 =DATE(RIGHT(A1;4);LEFT(A1;2);MID(A1;4;2))

To correct day/month:

 =DATE(YEAR(A1);DAY(A1);MONTH(A1))

Detect whether cell has date (dates are numbers, in Excel) or text:

 =ISNUMBER(A1)

Finally, all combined within one formula:

 =IF(ISNUMBER(A1);DATE(YEAR(A1);DAY(A1);MONTH(A1));DATE(RIGHT(A1;4);LEFT(A1;2);MID(A1;4;2)))

Just drag last formula from first row to end of your data and then format it as you wish (see @t.thielemans solution).

Select your data column and make sure they're highlighted. Go to Home>Number and select Custom and enter mm/dd/yyyy . You can also change the layout to one you want (mm-dd-yyyy/mmddyyyy/dd-mm-yyyy/...)

在此处输入图片说明

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