[Solved] Calculate the hours between two dates

Discuss the spreadsheet application
Post Reply
XsiSec
Posts: 2
Joined: Fri Nov 06, 2020 12:32 pm

[Solved] Calculate the hours between two dates

Post by XsiSec »

Hi Folks I have read a lots of topics about how to calculate hours between two dates, couldnt find anything that matched my requirements for 24 hours.

I need to calculate the amount of hours for each cell the red boxes is the answer.
Imagine
Days=Row1
W10=Row2


Image


then comes result Row=3

Could someone help me with a formula?

Thank you

Thank you
Last edited by MrProgrammer on Thu Nov 19, 2020 8:34 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
OpenOffice 6.1.52 OpenOffice 2.4 on Debian Buster
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: How to calculate the hours between two dates

Post by RusselB »

Welcome to the Forums.
The main problem you are having, is the fact that your entry for row W10 (which isn't a proper row number) contains a string that appears as 08:30-17:30
While math can be done with this, it is a lot more complicated.
It would be a lot easier to work with if you put your start time into one cell and your end time into another.
Then you just need to do a formula like End_Time - Start_Time
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to calculate the hours between two dates

Post by Zizi64 »

The date, time and the combined date-time values most be numerical types - if you want to use them in some calculations. I suggest you to use full date-time values fotr the Start time and for the End time (for example they can be located in two rows).
Then you will able to calculate the elapsed time value even between two days:

Row for Start values: 2020-11-05 23:00:00
Row for End values : 2020-11-06 01:00:00

formatted numerical result: End - Start = 2:00:00
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
XsiSec
Posts: 2
Joined: Fri Nov 06, 2020 12:32 pm

Re: How to calculate the hours between two dates

Post by XsiSec »

How could an example look if I had start and end time as well?
OpenOffice 6.1.52 OpenOffice 2.4 on Debian Buster
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to calculate the hours between two dates

Post by Zizi64 »

Here is a sample file with Date_Time and DateTime values.
Date_Time_DateTime.ods
(10.23 KiB) Downloaded 131 times
Check the applied custom cell styles.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to calculate the hours between two dates

Post by Villeroy »

I have attached a more extensive example.
Columns A through C take a date, start time, end time as numbers. I filled in 1000 random records from January 2017 until recently in random order. For the end result it is not relevant in which order or rows or columns are entered.
-----------------------------------------------------------------------------------------------
Column D calculates the duration. If the end time is earlier than the start time, one day is added to the negative results, so 20:00 - 3:00 gives 7 hours (-17 +24 hours)
Column E calculates the year from the date column.
Column F calculates the week number from the date column.
Column G calculates the week day name from the date column.
Column H calculates the week day number from the date column.
Once you have entered a numeric date into a cell, the program can calculate everything about that date. No need to enter week numbers or anything like that.
-----------------------------------------------------------------------------------------------
From the calculated columns I generated a pivot table which calculates the durations for every year, every week and for every week day too.
Attachments
Workshift_Pivot.ods
(99.17 KiB) Downloaded 109 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply