I’m trying to retrieve two dates from an article which are in a simple date format of 26-10-2007 and 28-11-2007 and when I run the below code it’s ’always’ making the end date the start date in one go! Please help!!
<?php
global $modx;
$job_desc_id = $modx->documentIdentifier;
$start_date_uts= $modx->getTemplateVar("start_date","",$job_desc_id,true);
$end_date_uts= $modx->getTemplateVar("end_date","",$job_desc_id,true);
$start_date = date("d-m-Y", mktime($start_date_uts[value]));
$end_date = date("d-m-Y", mktime($end_date_uts[value]));
echo $start_date_uts[value];
echo $start_date;
echo $end_date_uts[value];
echo $end_date;
$modx->setPlaceholder('start_date',$start_date);
$modx->setPlaceholder('job_end',$end_date);
$inidate = explode("-",$start_date);
$enddate = explode("-",$end_date);
$days = ($enddate[0] - $inidate[0]);
$months = ($enddate[1] - $inidate[1]);
$years = ($enddate[2] - $inidate[2]);
echo "<BR>Days:".$days;
echo "<BR>Months:".$months;
echo "<BR>Years:".$years;
?>
The extra Echos are in there to show me that even at a basic level it’s screwing up the fields before I do anything? It’s in a page alongside a whole world of TemplateVar checks but this little php snippet ain’t for sorting this.
Using Modx 0.95 btw.
Please help, and by all means, feel free to point out the glaringly obvious!!