Removing time element of Long Date Format

2019-07-17 02:27发布

I have a list of data within the last three years, but all the dates have different times on it. I am trying to write a macro that will delete all the times. I tried changing the format of the cell but it didn't work.

EX. the list looks like:

10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time
10/12/2011 08:41 PM Eastern Time

And I need to delete the 08:41 PM Eastern Time or equivalent from each. All the times are different though. Any thoughts?

5条回答
劫难
2楼-- · 2019-07-17 02:33

If actually date format, try =INT(A1) then format to suit.

This should cover either text or time format:

=IF(CELL("type",A1)="l",LEFT(A1,FIND(" ",A1)),INT(A1))  

or even:

=TEXT(IF(CELL("type",A1)="l",LEFT(A1,FIND(" ",A1)),INT(A1)),"mm/dd/yyyy")  

if the output is to be formatted mm/dd/yyyy.

查看更多
forever°为你锁心
3楼-- · 2019-07-17 02:44

Why not simply:

=Left(A1,10)

Assuming all dates look the same (mm/dd/yyyy) format

查看更多
地球回转人心会变
4楼-- · 2019-07-17 02:45

Just in case it isn't always the first ten characters (examples: 1/1/2011 or 3/14/12), you can use this formula. Be sure to format the cell as date:

=--LEFT(A1,FIND(" ",A1)-1)
查看更多
贪生不怕死
5楼-- · 2019-07-17 02:52

If the field is an excel date and not plain text, you can use the trunc function. It should trim the time portion off.

=TRUNC(A1)
查看更多
该账号已被封号
6楼-- · 2019-07-17 03:00

Not sure why this is not mentioned in any of the answers as its by far the fastest and easiest way to do this. You can use the DATEVALUE to convert the dates from text to an excel date if they are not already in an excel date format.

Once the date is in a number format (eg 42753.597534 which excel recognizes as January 18, 2017 2:20:27 PM): Excel equates dates to numbers and 1 is equivalent to 24 hours(1 day), while anything less than 1 is used for time. You can use ROUNDDOWN(A1,0) which will strip any non-integer part of the date which implicitly gets rid of the time (turning the above number into 42753 or January 18 , 2017.

查看更多
登录 后发表回答