简体   繁体   中英

converting 2/17/2013 10:37 AM to date format “MM/DD/YYYY HH:MM:SS” excel

I have a field in excel "Access date" I am trying to convert a text cell "2/17/2013 10:37 AM" when I try and use =text(A2,"MM/DD/YYYY HH:MM:SS") it returns the same value as I put in instead of 02/17/2013 10:37:00

Could anyone please advise?

Unfortunately, I think that Excel cannot recognize the date as you are in a country which does not support the mm/dd/yyyy format (eg European countries). Excel considers the value as text only.

The only way I know to convert it in date is to extract every piece of information in this text, using Excel text function. For example, given the value that you provide, you can try (assuming your value is in "A1"):

=DATE(VALUE(MID(A1;SEARCH("/";A1;SEARCH("/";A1)+1)+1;4));
LEFT(A1;SEARCH("/";A1)-1);
MID(A1;SEARCH("/";A1)+1;SEARCH("/";A1;SEARCH("/";A1)+1)-SEARCH("/";A1)-1))
+TIME(VALUE(MID(A1;SEARCH(" ";A1);SEARCH(":";A1)-SEARCH(" ";A1)))+IF(RIGHT(A1;2)="AM";0;12);
VALUE(MID(A1;SEARCH(":";A1)+1;2));
0)

That is quite a long formula... but the only way I can think of using Excel (should be a lot easier with R for example). This formula takes the assumptions that the year value is always 4 characters long, and that the minutes value is always 2 characters long.

If you want to convert it, you can then use TEXT function (or directly insert it in the previous formula) to transform your date in a text value (which is a bit odd). As I am working in France, the formula I need to use is the following (assuming I insert the first formula in "B1") :

=TEXT(B1;"mm/jj/aaaa hh:mm")

Note : in France "j" stand for "d" (days) and "a" stands for "y" (years)

Hope this helps

尝试将日期转换为日期值,然后将其格式化为日期:

=TEXT(VALUE(A2),"MM/DD/YYYY HH:MM:SS")

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