I've set up an edit column in the database, it stamps the correct time whenever a change is made to the database entry. For some odd reason whenever this datetime displays it displays 5 hours behind the time stamp in the database.

The only thing I can figure to do is add 5 hours to the time, but I can't seem to get any combinations from the online examples to simply add 5 hours to the stamp. Was hoping someone could help me out.

if ($comment->deleted == 1) {  } else { 

   $db = JFactory::getDbo();
   $db->setQuery('SELECT editdate 
                  FROM #__jcomments
                  WHERE id = ' . $comment->id .'');
   $edit = $db->loadResult();

   if ($edit > 0) { 
   echo JHtml::_('date', $edit, JText::_('l F j Y g:ia'));  } }

By default JHtml::date() accounts for user's timezone, which, if not set, defaults to site's timezone (set in Global Configuration). Pass another argument with value null to leave the date as is. Also, because you're using a hardcoded string for format, you don't need to wrap it in JText::_():

echo JHtml::_('date', $edit, 'l F j Y g:ia', null);

You should also remove first instance of $db->loadResult(). By having two of these you are running the query twice.

  • Thank you. Just curious, is that the same in every case? If you have a query and then $db->loadAssocList(); $a = $db->loadAssocList(); or $db->loadColumn(); $a = array_count_values($db->loadColumn()); can that first one always be gotten rid of? – Mythic Dec 19 '18 at 16:02
  • 1
    Yes. This true not just for JDatabase but for all PHP code. – Sharky Dec 19 '18 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.