Calculate difference between two times

CrazyBandit

New Member
Joined
Feb 21, 2017
Messages
3
Hello. I have a text string that represents a date and time that an employee has signed in. It is a long text string

(20170102205400) which represents 8:54:00PM 01/02/2017 I then have another time, punch out time:
(20170103070200)
I tried using the TIMEVALUE formula, and that did not work. Any ideas how I am to make a calculation of how many hours the employee has worked. NOTE: Sometimes they work overlapping days.

Any help is greatly appreciated. :confused::)

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
To convert your string into an Excel serial time, you could use the formula

=DATE(MID(A1,1,4), MID(A1,5,2), MID(A1,7,2)+TIME(MID(A1,9,2), MID(A1,11,2), MID(A1,13,2)

Then the two times can be subtracted.

Then, to convert back to your format,
TEXT(C1,"yyyymmddhhmmss")

Or you could use a custom format of yyyymmddhhmmss throughout and leave the entries as Excel serial time rather than strings.
 
Upvote 0
Thanks for the reply Mike. When I use the above formula, it brings the correct date back, however, the time is always 12:00AM. If I split up the Date and Time formulas then that returns the correct times but then I cn not calculate between the two time correctly because some employees work nights and will work form 01022017 at 11pm - 7am the following day.

Any Ideas?
 
Upvote 0
The following formula will covert your text string into an Excel date/time value (that is, a number).
Then, you can subtract one converted number from the other. The difference multiplied by 24 will give you hours.

=--TEXT(-(--A1),"0000-00-00 00\:00\:00")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

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