# BASIC function Now() refuses to return the date-time-stamp as Double (fractions of seconds, too).

I was working in Calc writing a piece of code in LibreOffice (V5.3.3.2) BASIC.
Suddenly the runtime function Now() did no longer return the 'Double' typed date-time-stamp, but a date-time rounded to full seconds.

Well, I found a description of Now() telling it returns its reult typed 'Date' and there is a text about the 'Date' type here (e.g.), which doesn't say anything sensible about the difference between the 'Date' and the 'Double' type. In specific there is no rounding mentioned. AND up to recently my BASIC Now() always returned also fractions of seconds as the Calc function NOW() still does.

Where can I find the background of the mystery?

edit retag close merge delete

Sort by » oldest newest most voted

The BASIC function Now() is described as returning its result as a value of type 'Date'. The type 'Date' I could nowhere find clearly specified. What I could find was gibberish, imo. The name itself also is, as the type is capable of keeping a date and a time as well at the same time. It should be named DateTime if used at all.

Sorry! It seems I didn't up to now stumble upon the fact that the type 'Date' if having assigned a date-time-value in 'Double' resolution always converts the value in a way that only full seconds are kept. Thus the BASIC type 'Date' and therefore also the BASIC function Now() will be useless for any technical application needing a higher resolution of time.

The Calc function NOW() produces and returns the date-time value as a 'Double' number allowing for a time resolution of about 1 ms (millisecond) for the next few centuries.

Needing high-resolution-NOW-values I only can suggest to resort to

myFA = CreateUnoService("com.sun.star.sheet.FunctionAccess")
highResDateTime = myFA.CallFunction("NOW", Array())


That's a silly detour, of course. Making Now() return the full achievable resolution and leving the rounding to the user should be a better way.

Of course, we have always to consider that a multitasking system may distort time analysis. This, however, is valid for a spreadsheet as it is for a BASIC routine.

more

Don't waste TIME with BASIC!

screen from browser-frontend with jupyter notebook backend

more

## Stats

Asked: 2017-06-25 15:30:30 +0200

Seen: 77 times

Last updated: Jun 26 '17