Splitting content of Excel cell into date & time

A question for the Excel wizards out there!

Didn't find your answer?

I have a spreadsheet of data extracted from a computer system.  The data includes a column of timestamps each of which I want to split into a date and a time.

Say in cell A5 I have (in general format)

2016-12-25-04.16.26.330000

I want to get in cell B5 (in date format DD/MM/YYYY) 25/12/2016 and in cell C5 (in time format HH:MM:SS) 04:16:26.

There are over 10,000 lines - so I don't want to do this by hand!  But I am sure you Excel wizards out there can show me a relatively easy way to do this.

Thanks in advance.

David

Replies (15)

Please login or register to join the discussion.

avatar
By gwilkinson
03rd Jan 2017 10:04

I would use the text to columns function, splitting by delimiter of - (dash), you will have cells with year, month day and time. Then split the text to column by delimiter . on the newly created time column.

You can then in new columns use functions of =DATE(year,month,day) and =TIME(hour, minute, second) referring to the relevant column to create date and time formatted cells.

Thanks (1)
By cheekychappy
03rd Jan 2017 10:33

Assuming that there are the same number of characters on each line, I would used fixed width rather than delimited when using text to columns.

Thanks (0)
David Winch
By David Winch
03rd Jan 2017 10:46

That's great, thanks a lot.
I have used
=DATE(MID(A5,1,4),MID(A5,6,2),MID(A5,9,2))
to get the date and
=TIME(MID(A5,12,2),MID(A5,15,2),MID(A5,18,2))
to get the time.
David

Thanks (0)
Replying to davidwinch:
Portia profile image
By Portia Nina Levin
03rd Jan 2017 10:59

Or even:
=DATE(LEFT(A5,4),MID(A5,6,2),MID(A5,9,2)), and
=TIME(MID(A5,12,2),MID(A5,15,2),RIGHT(A5,2))
if you're feeling confident that the date stamps are a fixed length format.

Does that really work though, without converting all the text extractions to numeric by using the VALUE function?

Thanks (0)
Replying to Portia Nina Levin:
David Winch
By David Winch
03rd Jan 2017 11:10

It has worked. The cells I am splitting were in general format - not text format, which may be the reason.
David
P.S. It returns #VALUE! where I am attempting to split a blank cell.

Thanks (0)
By Democratus
03rd Jan 2017 10:48

Just an alternative, text to column will work anyway.
@left(A5,10) in B5 will return the 1st 10 characters of the cell (assumng no dashes in between the numbers - adjust accordingly). Then format the return cell as date.
@right(A5 ,15) in C5 will return the other time element, format cell accordingly. Again assuming no spaces in between dashes

Happy New Year

Thanks (0)
avatar
By User deleted
03rd Jan 2017 10:59

AccountingWeb, doing what was intended!

A treat to witness.

Thanks (2)
By alan.rolfe
03rd Jan 2017 11:06

Assuming that the data is actually dates when imported into Excel, you could simply use the TEXT function to extract the date and time.

For example, the date would be =TEXT(A1,"dd/mm/yyyy")
and the time would be =TEXT(A1,"hh:mm").

If Excel does not import that data as dates you may need to mess around with the string formatting functions, but usually Excel can import OK if the data is consistently formatted.

Thanks (1)
Replying to alan.rolfe:
avatar
By David Winch
04th Jan 2017 11:23

Looks like Occam has been sharpening his razor!

I'm the Sales & Marketing Consultant from Cambridge!

Thanks (0)
avatar
By paulwakefield1
03rd Jan 2017 12:06

Power Query (Get and Transform in Excel 2016) would also provide an effective solution without the need for formulae. The query would need to be built but it is simple.

More detail is probably superfluous at this stage as the question has been answered but always fun to see how many different ways a problem can be tackled. :-)

Thanks (0)
avatar
By Bubz
04th Jan 2017 11:50

If it's an actual Excel date/time, rather than a text string, it's even easier:

For a date/time in e.g. cell A1, the formula =int(A1) will give the date, and the formula =A1-int(A1) will give the time. You will then need to format the cells as dates and times to view them more sensibly.

Thanks (0)
Replying to Bubz:
By Democratus
04th Jan 2017 12:44

I like this. never heard of it. fantastic little formula.

Thanks (0)
Replying to Democratus:
Portia profile image
By Portia Nina Levin
04th Jan 2017 13:38

I take it you have come across SUM? which is also very useful.

Thanks (0)
Replying to Portia Nina Levin:
David Winch
By David Winch
04th Jan 2017 14:41

Many years ago I remember walking past a police financial investigator who was busy at his desk with a calculator adding up a column of figures in an EXCEL spreadsheet on his screen so he could type in the total at the bottom. (No kidding!)
Obviously Portia if you had been there you could have helped him out ....
David

Thanks (0)
Replying to davidwinch:
Portia profile image
By Portia Nina Levin
04th Jan 2017 14:47

I have worked with somebody that did the very same thing, David. And As far as I know, he has never been a police financial investigator.

Thanks (0)