SOLVED

Convert custom date format <day> <hour>:<minute>:<second> to something workable in excel?

Copper Contributor

hi Team,

 

looking for some help here!  have a data file which has 3 columns measuring a specific time and I need to calulate the difference between them.  the challenge i'm having is that the format in the file is as follows:

 

<day> <hour>:<minute>:<second>

 

I need to calculate the number of seconds between each stage, can you help???

Even if I minus the two, if stage 1 is at 3 23:55:13 and stage 2 is at 4 00:05:25 (ie #1 is before midnight and #2 is after) then i get weird negative values.  sample below.

 

any ideas?

 

Customer placed order datetimePlaced order with restaurant datetimeDriver at restaurant datetimeDelivered to consumer datetime
01 02:52:1201 03:00:2501 03:08:0901 03:35:20
13 15:58:5713 17:56:4513 18:24:3913 18:57:01
17 19:02:3717 19:12:5117 19:19:5917 19:31:09

 

 

 

11 Replies

OK so apparently the HTML didn't like my message content...

 

the structure is as follows:

 

 "<day> <hour>:<minute>:<second>"

@zachary_king355 

That is just format, but what are the values - texts as in your sample or datetime formatted as

 d hh:mm:ss ?

thanks @Sergei Baklan - if i understand correctly, it is date time in the format you suggested d hh:mm:ss

@zachary_king355 

If that's datetime formatted as here

image.png

you shall have correct result in seconds, formatting it as [ss].

 

If not, perhaps you may attach sample file.

thanks @Sergei Baklan not sure what im doing wrong but get an error message.

 

sample file attached...

best response confirmed by zachary_king355 (Copper Contributor)
Solution

@zachary_king355 

You have texts, not datetime (which is actually an number in Excel). To receive the difference in seconds you need to parse these texts like

=IFERROR((LEFT(D5,2)-LEFT(C5,2))+RIGHT(D5,8)-RIGHT(C5,8),"")

and apply to the resulting cell [ss] custom format.

IFERROR returns empty string if you have error in result, that happens if one of the texts is empty.

 

Alternatively you may keep General format and convert result to seconds as

=IFERROR( (LEFT(D5,2)-LEFT(C5,2)+RIGHT(D5,8)-RIGHT(C5,8) )*60*60*24,"")

 

Please check in attached file.

@Sergei Baklan 

How to deal with negative values in this case? especially when there 24hrs overlap ?

Which exactly case do you mean? The question was about converting text to datetime.

@Sergei Baklan 

Yes. I followed your recommendations but I have some instances where I have negative values in my calculation.

You will find some examples in the columns highlighted in red (calculated) in my dataset

@Dezmaster2020 

Thank you for the file, but it's logic is not complete. We don't know what is the last day of the month, 31 as in Jan, or 28 as in Feb this year, or 29 as in Feb of the leap year. Other words, we need year and month in addition.

 

With current information we may assume that if restaurant datetime is on next month compare to  customer datetime then customer datetime is always on the last day of the month. With this formula could be

=IFERROR(  (  IF( LEFT(B2,2)<LEFT(A2,2), LEFT(B2,2), LEFT(B2,2)-LEFT(A2,2) )+(TIMEVALUE(RIGHT(B2,8))-TIMEVALUE(RIGHT(A2,8))) )*24*60, "")

But that gives wrong value if, for example customer place order on Feb 27 and restaurant - on Mar 01.

That could be the case, for example in row 16666 we have

28 06:14:16 30 00:57:01

So, to do reliable calculations year/month are required.

Please check second sheet in attached file. 

1 best response

Accepted Solutions
best response confirmed by zachary_king355 (Copper Contributor)
Solution

@zachary_king355 

You have texts, not datetime (which is actually an number in Excel). To receive the difference in seconds you need to parse these texts like

=IFERROR((LEFT(D5,2)-LEFT(C5,2))+RIGHT(D5,8)-RIGHT(C5,8),"")

and apply to the resulting cell [ss] custom format.

IFERROR returns empty string if you have error in result, that happens if one of the texts is empty.

 

Alternatively you may keep General format and convert result to seconds as

=IFERROR( (LEFT(D5,2)-LEFT(C5,2)+RIGHT(D5,8)-RIGHT(C5,8) )*60*60*24,"")

 

Please check in attached file.

View solution in original post