UTC Timestamps: Why Dates Show Wrong in Your System

Headline reading 'Timestamps look simple. Until the date is wrong.' with the labels UTC, Time zones, Dates and Store in UTC

There is one concept which is obvious to those who know, but others remain oblivious to it: timestamps.

Life is easy, until you build it

In a non-coding environment, life is easy. Devices and applications always show us the time according to where we are. But when you are the one supposed to be doing it, we tend to forget that timestamps may change if we are not careful.

UTC is the standard that works as the baseline. Coordinated Universal Time. SA and Mozambique time is UTC plus 2 hours.

When working on systems built for our own time zone, we usually do not think much about timestamps. But when timestamps are the key concept of your application, things may go wrong.

Where UTC timestamps go wrong

Consider this scenario. I want to record the timestamp of an entry I made, and then show it as the date of entry. Take note that some databases now enforce UTC or ISO times as their default for storing timestamps, but without being careful, there are two places where things go wrong.

1. Not converting when showing. Say I make an entry at 03/11 00:00 my time (UTC+2). If the database enforces the time zone, it records it correctly. However, when displaying it to the user without converting it to local time, it will show 02/11 22:00. So what is supposed to be an entry on 03/11 is now on 02/11. Try building a hotel system with such errors: check-ins go wrong, check-outs go wrong, and so on.

2. Not storing in UTC. If you put the entry in as it is, some databases may assume it is already UTC. Your timestamps are already incorrect, and you need conversions to fix it.

In short, always use UTC for timestamps, avoid the headaches, and stick to one measure.

This is one of the common errors among students too.

Dates looking wrong in your system?

One Click Solutions can find out why, in plain language. The first 15 minutes are free.

Book a free intro call

Discover more from One Click Solutions

Subscribe to get the latest posts sent to your email.

  • Share:

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href=""> <abbr> <acronym> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Send a Message

Discover more from One Click Solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading