There has always been a confusion for a developer on how to use dates in Joomla, specially when all the time zones have to be taken into consideration.

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!

Read more

© 2024 Extly, CB - All rights reserved.