0
votes

I have a column with date and time for start (IN) and end (OUT) and I want to calculate the difference in days.

Date:  IN   Time:  IN   Date:  OUT  Time:  OUT
24/07/2018  12:15:00    26/07/2018  06:11:00

I combine them into date time IN and OUT by using:

E1=TEXT(A2,"dd/mm/yy ")&TEXT(B2,"hh:mm:ss")
F1=TEXT(C2,"dd/mm/yy ")&TEXT(D2,"hh:mm:ss")

But I am unable to find any working code for the difference in number of hours.

2

2 Answers

2
votes

TEXT will convert your dates and times into text (strangely enough).

Adding the date and time will return a date/time value so you could use:
=SUM(C2:D2)-SUM(A2:B2) to return 1.74722222
(edit: if you then give the cell a custom number format of d:h:mm it will display 1:17:56 or 1 day, 17 hours, 56 minutes).

(EDIT AGAIN: Sorry, only just seen you want it in hours. Give the cell a custom number format of [hh]:mm. The square brackets tells it to count over 24 hours. This will return 41:56).

or

=DATEDIF(SUM(A2:B2),SUM(C2:D2),"d") to return 2.

or if you just want days from the dates you could just use
=C2-A2 to return 2.

Dates and times in Excel are just numbers - no need to complicate things by turning them to text.

1
votes
= (F1 - E1) * 24

Rather easly :)