Bug 135505 - Calc: Maths with date off by one day in the afternoon
Summary: Calc: Maths with date off by one day in the afternoon
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.3.6.2 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-06 16:45 UTC by simon
Modified: 2020-08-06 17:17 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description simon 2020-08-06 16:45:24 UTC
Description:
The calculation based on the date gives a different result in the morning to the afternoon.

Steps to Reproduce:
1. Cell G1:   =NOW()  Assume it is 06/08/20
2. All other G Cells  I put a Date  say G307:   06/08/2020
3. N307:  =IF(ISBLANK(M307),IF(G307<>"",(G307)-G$1,""),"COMPLETE")
4. In the morning N307 is blank , in afternoon N307 is -1

Actual Results:
In the morning it gives the result I expect, if the date in the G column is the Same as todays date then the N column is blank.  In the afternoon the N column reads -1 but G1 is still stating the correct date.

This has been the case for may versions of Libreoffice.  Same results on different Laptops

Expected Results:
I would expect the N cell to remain the same all day


Reproducible: Always


User Profile Reset: No


OpenGL enabled: Yes

Additional Info:
[Information automatically included from LibreOffice]
Locale: en-GB
Module: SpreadsheetDocument

OS: Windows 10 pro
OS is 64bit: YES
Comment 1 Mike Kaganski 2020-08-06 17:17:02 UTC
(In reply to simon from comment #0)
> 1. Cell G1:   =NOW()  Assume it is 06/08/20

No, it is not "06/08/20". NOW [1] returns not a day, it returns a datetime value - i.e., day *and time of the day*, the latter as a fraction of a day. So e.g. for now, =NOW gives me 2020-08-06 20:10:48, which is 44049.8408352431 internally; and the ".8408352431" is "afternoon" (i.e., 20:10:48).

If you format your cell to show you only whole part of the datetime value (i.e., only date), you do not change your calculations, which still see the actual value stored in the cell, not the result of formatting.

Also it looks like you have formatted N307 to not show you fractional part, so it rounds the result of the subtraction, and ".8408352431" is shown as "1", while "0.23456" is shown as "0".

You likely need to use TODAY [2] instead of NOW.

Closing NOTABUG.

[1] https://help.libreoffice.org/6.4/en-US/text/scalc/01/func_now.html
[2] https://help.libreoffice.org/6.4/en-US/text/scalc/01/func_today.html