Joomla Timezone/German time

31 views
Skip to first unread message

Timotheus Titus

unread,
Jul 1, 2015, 10:38:16 AM7/1/15
to joomla-de...@googlegroups.com
Hello,

I would like to check the time within a sub controller's method. The calendar field in my JForm saves the datetime to sql and uses UTC as filter. So now we have 16:37h in Germany and in the database would be stored "2015-07-01 14:37:00".

Well, fine.

Now I'm using DATE_FORMAT_LC2 in my views to print the time in "German time". This works fine, too.

Now my controller wants to check if the entry is older than current time. Unfortunately I always get "2015-07-01 16:37:00", the time that is saved in the database, when calling $this->savedtime;

How can I "generate" the german time in my controller? At this moment this is my source:

$now            =           JFactory::getDate();            
$itemdate       =           JFactory::getDate($item->savedtime);

if($now > $itemdate)
{
//do fancy stuff
}
How can I solve this?

Søren Beck Jensen

unread,
Jul 2, 2015, 3:40:57 AM7/2/15
to joomla-de...@googlegroups.com
I always find that using SQL for time comparison is the easiest way. Is there a solution where you could use the NOW() function in SQL?


It also works great when saving date/time. Instead of saving php's time() function, save using MySQL's NOW() function.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Bakual

unread,
Jul 2, 2015, 6:32:24 AM7/2/15
to joomla-de...@googlegroups.com, spqrinco...@gmail.com
You should never do calculations with the german date. That's just a display thing.
Work with the english format as it is stored in the database. To do calculations with it in PHP, you need to convert it into a timestamp first. That one will show the seconds since 1970-01-01 00:00:00.
To do that, use strtotime and pass it the english date. Then do the calculations and coonvert it back using date

Allon Moritz

unread,
Jul 2, 2015, 7:32:20 AM7/2/15
to joomla-de...@googlegroups.com

German time is $itemdate->format('c', true); the true parameter formatey the date in the timezone set on the date itself.

--
Reply all
Reply to author
Forward
0 new messages