Login / Logout


How to convert local date to GMT with Joomla

Store local date as GMT (UTC) with Joomla Framework

This is what you should do to store date in database with Joomla. You convert local date to GMT (UTC) before updating the database.

// Convert local date to UTC when storing to database
// (Say the variable $date stores local date)
$tz = JApplication::getCfg('offset');
$date = new JDate($date, $tz);
$table->example_date_field = $date->toMySQL();

Use JHtml::_(‘date’, $date, ‘%d/%m/%Y %H:%M’) to display as local date.

You should add this functionality to your helper class to let you do the job easier.

Does Joomla framework actually provide this functionality as method, though?

About the Author

Hiro Nozu

Hiro Nozu is a web developer who specializes in building CMS websites with Joomla. He has been in the field for over 10 years, and has been loving every minute of it. Check out some of his past work. He developed the extension Easy Search after the 3 months of involvement in the CMS at iFactory.

Comments (0)

Leave a comment

Please login to leave a comment. Optional login below.