created_at (server time) is sometimes earlier than clicked_at (client time) — why?
06:02 27 Mar 2026

I’m tracking button clicks on my website and storing both client-side click time and server-side insert time in my database.

Frontend (JavaScript)

I capture the click timestamp like this:

clicked_at: Date.now() // milliseconds

Backend (PHP)

On the server, I convert and store it:

if (isset($clicked_at) && is_numeric($clicked_at)) {
    $clicked_at = date("Y-m-d H:i:s", $clicked_at / 1000);
}

$created_at = date("Y-m-d H:i:s");

Database Example

created_at  = 2026-03-27 16:22:03
clicked_at  = 2026-03-27 16:22:04

Issue

In some cases, clicked_at (client time) is later than created_at (server time), even though logically the click happens before the server receives the request.

Expected

clicked_at <= created_at

Actual

clicked_at > created_at

Additional Info

  • Client sends data using navigator.sendBeacon() or fetch()

  • Server timezone is set to Asia/Kolkata

  • clicked_at is generated using Date.now() (client machine time)


Question:

Why does this happen, and what is the correct way to handle or normalize timestamps between client and server?

Should I:

  1. Trust client time (clicked_at)?

  2. Trust server time (created_at)?

  3. Or calculate latency and adjust?


Any guidance on best practices for tracking accurate event timing would be appreciated.

php