I've got the following code in a snippet :
<?php
$resource = $modx->getObject('modResource', $id);
if(!$resource) return;
$date = $resource->getTVValue('timerData');
$remaining = $date - time();
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
return $modx->getChunk($tpl, array('days' => $days_remaining, 'hours' => $hours_remaining));
$date gets its value from timerData which is a template variable and thus adjustable by users. I've set the input and output both to date but as a result i get a timer which counts down from -15000+ days and hours. How does this happen? It works fine without the tv but then its not manageable without diving into the code. Any suggestions/solutions would be appreciated. Cheers Marco
The actual input of the tv return : 2014-07-10 00:00:00 while as the script part returns : -15832 days and -13 hours (days and hours are manually written seeing as the actual values are $days and $hours from the php script)
Just convert tv input to timestamp:
$date = $resource->getTVValue('timerData');
list ($d, $m, $Y, $H, $M, $S) = sscanf($date, "%2d-%2d-%4d %2d:%2d:%2d");
$date = mktime($H, $M, $S, $m, $d, $Y);