The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.

A developer's guide to Use Dates in the right way in Joomla!

A developer's guide to Use Dates in the right way in Joomla!

When you are handling date and time, its likely that a developer might get confused on what is the right way to handle multiple timezones.

Let’s make this Crystal Clear!

As you can see in the Image below, the date selected is 2015-08-26 05:30:00, This is the user’s timezone date and time.

Joomla Date Filter

If we save the same date in our database it would mismatch for the person who is sitting on the other corner of the world.

Hence, a better way to do this is to save the date in UTC format.

For Instance

If the user is in India and the time in here is 2015-08-26 05:30:00, as India is +5.30GMT save the time as 2015-08-26 00:00:00 in your database. Which is the selected time ( 05.30).

While displaying the date you need to make sure that you convert the UTC date to the user’s local timezone.

This way you make sure that wherever the user is, the time shown to him is accurate.

For Instance

UserA is India and creating an event with start date 2015-12-01 17:30:00 which is 1st Dec 2015 at 5.30pm

UserB is in London (GMT +1:0)

UserC is in New York (GMT -5:0)

UserD is in Australia (GMT +10:00)

Here are the dates shown for different user

Date saved in database - 2015-12-01 12:00:00 (This is the UTC time)

Date shown for UserB - 2015-12-01 13:00:00 (This is GMT +1:00)

Date shown for UserC - 2015-12-01 07:00:00 (This is GMT -5:00)

Date shown for UserD - 2015-12-01 22:00:00 (This is GMT +10:00)

Hope this Blog  clears all the confusion and now you will be able to use dates efficiently in Joomla!

Rate this blog entry:
SocialAds 3.1. First Look!
In Conversation with Erik Folberth: From Creating ...