Time interval between 2x dates/hours

Have a spreadsheet with a Date column, and an hour/minutes (24hr) column, and would like to be able to have a 3rd column of the difference. eg
image

So, in the interval column, C3, would like to calculate the difference in days:hours, between Row2:(Date/Time) and Row3:(Date/Time) 13:21:10 (I think??? :slight_smile: ) As in 13days:21Hours:10mins.
Thanks.

Internally Calc saves dates as number of days since begin of the 20th century and time as fractions of a day, so 6:00 is 0.25 and 12:00 is 0.5 resulting in 1 for 24 hours. This design allows to add and subtract dates/times quite easily.
=A2+B2 would give you a timestamp and you can use the difference to other timestamps like
=(A3+B3)-(A2+B2)
.
For your differenc the part left from the decimal points is your number of days, the fraction to the right will represent hours/minutes. (Edit: above image by @PKG shows how to convert this to a text-string yourself)
.
Problems are lurking, if cells “look like” date/time, but are effectivly strings (text) and don’t try to use the same format-codes as column A or B in C.

2 Likes

:thinking:

is it ? 12/30/1899

ok, let’s see if basic references can consolidate goodwill paraphrasing :wink:
Date & Time Functions

Fraction - Wikipedia :thinking:

the question could be : why there’s no format code able to simply properly display a time interval with days ??!! would avoid these string concats.

Number Format Codes

Also for date difference we can use custom number format DD:HH:MM.

… which can’t give “123:04:05” :wink:

1 Like

Don’t tell such fairy tales!

3 Likes

Yes, the above format will work correctly as long as the number of days is not more than 31.

which is a big gap :face_with_thermometer:

anyone knowing why there’s no [DD] ? similar to [MM] or [HH]
maybe an ODF pointer ?

NO it never return correct results:

duration in days as »D« day of month
1 31
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
2 Likes

Yes, I agree, I wrote nonsense.

1 Like

because [brackets] doesnt change the meaning of D from day of Month into duration of days

thanks !! :sos:

question is why it has not been requested / implemented since it’s a reasaonnable as HH … :thinking: )

The ODF is not a problem (even though it discusses only hours/minutes/seconds in context of durational format). More important is - there’s no requests (at least not easily found), and - if introduced - inevitable incompatibility with other spreadsheet apps.

2 Likes

@erAck any thought here ?

What about? It could be possible to implement it in LibreOffice if it was defined by ODF at the cost that it wouldn’t work in Excel nor any other .xls|.xlsx or format codes reading application, or could even make the document fail to load properly when read by such if it checked.

Note that Mike’s link yields 404 now as it was an interim candidate standard version, the final release’s attribute section is Open Document Format for Office Applications (OpenDocument) Version 1.3. Part 3: OpenDocument Schema

Don’t know if I should post this as a solution.
disask119426DateTimeIntervals.ods (33.9 KB)
The most important additional hint: Never use a TOD format like HH:MM:SS what unfortunately is a kind of standard though it hides a possibly existing integer part which may go back to a slightly trembling finger during input.
Since we have lots of related questions over the years (here and also in the AOO forum), and contributors have already wasted thousands of hours with inventig (re-inventing) little wheels just modified to support any very special need, I feel tempted to teach about the reasons for such a mess.
Surely it is not the lack of support for a “[DD]” format code. Dates are dates after all, and everybody should know the clever way to write them (ISO 8601), but few do…
Well, decide yourself if the suggestions, formulas, and explanations contained in the attached document are of some use, or just another example for wasted time.
Oh my! Even the British managed to get rid of their outdated currency system with funny subdivisions of 20, 12, and … more (coins). But:
Part of the mess with TOD (TimeOfDay) and durations goes back about 4000 years when a then progressive civilisation preferred subdivisions by 60 (“sexagesimal”). This was rather clever then because the divisor contained all the factors 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 what helped to avoid calculations with additional fractions in many cases. Later Leibniz considered a base of 12 better than the 10 we are using for the same reason.
Now computers do the calculations for us without complaining about a base o 10 or one of 2 (though there are disadvantages of the dyadic system, too).
A centiday (1cd = 1d/100 = 14.4 min = 14 min 26 s) would be a handy unit, wouldn’t it? Just wait another 1000 years.

1 Like

indeed :neutral_face:

please enjoy ISO 8601 - Wikipedia #Ordinal_dates :

An ordinal date is an ordinal format for the multiples of a day elapsed since the start of year. It is represented as “YYYY-DDD” (or YYYYDDD), where [YYYY] indicates a year and [DDD] is the “day of year”, from 001 through 365 (366 in leap years).
For example, “1981-04-05” is the same as “1981-095”.

1 Like

Tank you for reminding. I once read about this - and put it away somewhere in the backyard of my memories.
Anyway: Even a date format numbering the days of a year without further subdivisions is a date, but not an extended duration format.