SQLite Forum

Is date/time atomic per statement/transaction?
Login
iCurrentDate stores the "integer milliseconds since the beginning of the julian epoch" so it stores the "Current Time" to the millisecond within the accuracy of the hardware/system clock.

The system call used to retrieve "now" on non-windows systems returns the current system clock time precise to at least the millisecond (and often with finer ganularity).  (Though I suppose it may or may not be updated continuously and may suffer the same granularity issue as windows).

On Windows systems, however, even though the GetSystemTimeAsFileTime API used to retrieve the system clock has a granularity of huns (hundreds of nanoseconds), it is only "updated" once per tick (usually 15 ms depending on the hardware) or as specified by the kernel timer frequency.

The long and the short of it is that the value of "now" as representing the machine concept of the time "right now" is subject to many vagaries of the OS as well.

My local branch of SQLite3 includes a patch to os_win.c that creates a new define SQLITE_USE_PRECISE_TIME that replaces the call to GetSystemTimeAsFileTime with a call to GetSystemTimePreciseAsFileTime so that the returned value does not depend on the system timer frequency.  (Note that this API is only available on later versions of Windows).

```
Index: src/os_win.c
==================================================================
--- src/os_win.c
+++ src/os_win.c
@@ -753,11 +753,15 @@
   { "GetSystemTime",           (SYSCALL)GetSystemTime,           0 },

 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)

 #if !SQLITE_OS_WINCE
+#ifdef SQLITE_USE_PRECISE_TIME
+  { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimePreciseAsFileTime, 0 },
+#else
   { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
+#endif
 #else
   { "GetSystemTimeAsFileTime", (SYSCALL)0,                       0 },
 #endif

 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
```