Datediff using local time

thellie

Member
Hi,
I've had to adjust my date plugins to local time in order to get the correct date input - I'm in Thailand so its being input -7 hours (ie I input 1 Jan 2018 - date only, no time), and 31 Dec 2017 17.00.00 is added to the dbase.

But I need to create a date comparison field to get "duration of stay", and I'm stuck on the php syntax - it is returning 0 - could someone please show where I'm going wrong?

$enddate = '{vol_appform___enddate}';
$startdate = '{vol_appform___startdate}';
$tz_from = 'Asia/Bangkok';
$tz_to = 'UTC';

$end = new DateTime($enddate, new DateTimeZone($tz_from));
$end->setTimeZone(new DateTimeZone($tz_to));

$start = new DateTime($startdate, new DateTimeZone($tz_from));
$start->setTimeZone(new DateTimeZone($tz_to));

$datediff = ($start - $end);
$diff = round($datediff / 86400);
return $diff;

Thanks :)
 
I figured out my webhost is overriding the timezone... despite me changing it in the php.ini, .htaccess, and joomla settings.
I dropped a phpinfo.php file into my directory and it showed my timezone as America/Chicago.

Solved it by doing the following:
Add this to the top of the .htaccess file in the public_html root folder
Code:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home1/username
<Files php.ini> order allow,deny
deny from all
</Files>
</IfModule>
nb - make sure you check the 'home' part as well - mine is home1

If your timezone is already set in your php.ini file, then it should show up now...

So, now I have to go back and revert all my local time to UTC...
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top