Convert a string into date - hour

Dan89

New Member
Joined
Apr 16, 2014
Messages
2
Hey guys, I need some help.

I have 2 separated cells with these STRINGS, indicating date and hours:

Apr-14-14 00:31:41
Apr-15-14 00:29:41

I would like to calculate, in a third cell, the difference between the 2 date/hours (in seconds).

How can I convert these 2 string cells into a date + hour format, so that I can compute the difference?

My version of Excel is 2013.

Thank you.
 
But I assume that the OP is using a date setting where month precedes the day, as in the U.S. (?)

Regards

Hi XOR LX,

'APR' and/or the hyphens does/do not get picked up is U.S. Excel. (the date as a semi-string would not meet 'local expectations' with a hyphen, and is not handled)

Mark
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi XOR LX,

'APR' and/or the hyphens does/do not get picked up is U.S. Excel. (the date as a semi-string would not meet 'local expectations' with a hyphen, and is not handled)

Mark

Ah, interesting. Thank for that, Mark.

Such inconsistencies as we have to endure across this pond!

Cheers
 
Upvote 0
Why not just:

=A2-A1

?
'APR' and/or the hyphens does/do not get picked up is U.S. Excel. (the date as a semi-string would not meet 'local expectations' with a hyphen, and is not handled)
Such inconsistencies as we have to endure across this pond!
@XOR LX,

Does "=A2-A1" really work for you in your given Locale? Just out of curiosity, what about this (the formula I posted in Message #6), does it work for you or not?

=SUBSTITUTE(SUBSTITUTE(A2,"-"," ",1),"-",", ")-SUBSTITUTE(SUBSTITUTE(A1,"-"," ",1),"-",", ")
 
Upvote 0
@XOR LX,

Does "=A2-A1" really work for you in your given Locale? Just out of curiosity, what about this (the formula I posted in Message #6), does it work for you or not?

=SUBSTITUTE(SUBSTITUTE(A2,"-"," ",1),"-",", ")-SUBSTITUTE(SUBSTITUTE(A1,"-"," ",1),"-",", ")

Both work, providing of course I amend the strings given to:

14-Apr-14 00:31:41
and 15-Apr-14 00:29:41

(formatting as text, of course.)

Regards
 
Upvote 0
This version should convert in both UK and US

=SUBSTITUTE(MID(A1,5,99),"-","-"&LEFT(A1,4))+0

Yes, but the interesting point seems to be that, within the correct locale, it is not necessary to first perform any such conversions on the equivalent "Little-endian" version of the given text.

Regards
 
Upvote 0
Both work, providing of course I amend the strings given to:

14-Apr-14 00:31:41 and 15-Apr-14 00:29:41
(formatting as text, of course.)
Okay, so that means the "mmm d, yy" or "mmm d, yyyy" format is only recognized on my US system... good to know. Thanks.

This version should convert in both UK and US

=SUBSTITUTE(MID(A1,5,99),"-","-"&LEFT(A1,4))+0
Thanks for the "universal" format. Briefly playing around with this format shows you can reduce your formula by 4 characters as this appears to also work...

=SUBSTITUTE(MID(A1,5,99),"-",LEFT(A1,4))+0

An alternate way to perform the same rearrangement of date parts (the way your formula does) is like this...

=(MID(A1,5,2)&LEFT(A1,3)&RIGHT(A1,13))+0

It trades your SUBSTITUTE function call for a RIGHT function call... would I be wrong in assuming that the RIGHT function is less "expensive" than the SUBSTITUTE function?
 
Upvote 0
Of course, all this could be avoided if an adherence to logical thought re date formats prevailed universally :cool:
 
Upvote 0

Forum statistics

Threads
1,216,094
Messages
6,128,785
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top