Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

Importing CSV into Excel

I am simply importing CSV into Excel, In which I have a date column. it seem like this.

10.22.2014 13:34:00

When I am finish Importing Now I want to convet the whole date column to look like this in the format cell section but it is not working for me. Can you suggest another way. What can be the main reason SUppose i put a formula on the column then Everytime user import the data he need formula which might be not a good idea, Is there something I can do when I m importing or just like wondering what could be done?

10/22/2014 1:34:00 AM or PM

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's one approach:

  1. Substitute dots with slashes
  2. Use DATEVALUE, TIMEVALUE functions on relevant subsections of this substituted string. Subsections are fetched using LEFT and RIGHT string functions.
    1. These return a serial number for dates (days since 1900) and time (a floating point between 0 and 1). When summed, the value can be represented as both date and time, in a format of your choice, as shown below:

enter image description here

Or, showing formulas:

enter image description here

EDIT: adding all-in-one formula. Note that this will give you the serial value (41934.5652777778), which can then be formated using the built in formats for dates / times--just select the one you want. This does not actually render a string:

=DATEVALUE(LEFT(SUBSTITUTE(A1,".","/"),10))+TIMEVALUE(RIGHT(SUBSTITUTE(A1,".","/"),8))

enter image description here

If, however, you do want a string returned, you can use the TEXT function.

=TEXT(DATEVALUE(LEFT(SUBSTITUTE(A1,".","/"),10))+TIMEVALUE(RIGHT(SUBSTITUTE(A1,".","/"),8)),"m/d/yyyy h:mm AM/PM")

(This is done in libreoffice, but the same formulas and arguments exist in MS Excel)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...