codependent
codependent

Reputation: 24472

Number of days (including decimals) between two OffsetDateTime's

Given two OffsetDateTimes we can calculate te number of days with:

DAYS.between(createdDateTime, finishDateTime)

This returns an absolute value of days with the difference between: 2020-03-15T10:51:24.608+00:00 and 2020-03-17T09:36:17.001+00:00 being 1.

However I need to get the exact difference including decimals, something like 1.9xxxx or so in this case. How could this be done?

Upvotes: 1

Views: 458

Answers (1)

codependent
codependent

Reputation: 24472

I was looking for an out-of-the-box solution but as Michael pointed out in the comments something like this works perfectly:

(ChronoUnit.HOURS.between(createdDateTime, finishedDateTime) / 24.0)

Upvotes: 2

Related Questions