functionlibreoffice-calcmillisecondsseconds

LibreOffice Calc SECOND function returning wrong value - why?


I have a table with a timestamp column (column A) that contains the timestamp with millisecond resolution.

Example:

enter image description here

I have separate columns for extracting different time 'components' (year, month, date, etc.), but the seconds column (SS) is giving the wrong value for the rows highlighted in red.

The formula for column SS is simply: =SECOND([timestamp_column]), for example in row 2, it is =SECOND(A2)

Why is it giving the wrong value for some rows?


Solution

  • It dawned on me upon looking closely that for all rows where the SECOND function returns the wrong answer, they are all the correct SECOND value +1. Looking at the milliseconds in the source column, I realized that they are all 500ms or more 'past the second'...therefore, the SECOND function must be ROUNDING.

    The ONLY indication of this is nothing more than implied here: enter link description here

    where is says:

    enter image description here

    That is the only use of the word "ROUND" on the entire page.

    The formula to workaround this behaviour (which is not a bug, it is just obtuse) is:

    =SECOND(INT(A2*86400)/86400)

    which truncates the milliseconds off the source, or

    =TEXT(SECOND(INT(A2*86400)/86400),"00")

    if you want it formatted as a double digit.

    The table now correctly extracts the 'CURRENT SECOND' of the timestamp in question, instead of the 'NEAREST SECOND':

    enter image description here