Hi,
I would to save a dif between 2 date
in Data override on Update
duration:DATEDIFF(end_date, start_date)
but chrono send query to mysql with '
`duration` = 'DATEDIFF(end_date, start_date)'
Thanks
Do the date difference in PHP.
Hi healyhatman,
in chrono function php
$d1 = new DateTime( $this->get('d1') );
$d2 = new DateTime( $this->get('d2') );
$interval = $d2->diff($d1);
echo $interval;
produces a white screen !!!
Well of course, don't you mean $this->data ? And you'll want to check to make sure d1 and D2 end up as valid dates first before trying diff
$d1 = new DateTime( $this->get('d1') );
$d2 = new DateTime( $this->get('d2') );
//$interval = $d2->diff($d1);
var_dump( $d1 > $d2 );
echo "<p>" . $this->get('d1');
echo "<p>" . $this->get('d2');
echo $interval;
result is :
bool(true)
2018-12-31
2018-12-01
this is correct...
$d1 = new DateTime( $this->get('d1') );
$d2 = new DateTime( $this->get('d2') );
$interval = $d2->diff($d1);
$interval->format("%a");
echo $interval;
always white screen
Turn your error reporting on then buddy to find the problem
Catchable fatal error: Object of class DateInterval could not be converted to string in ...../libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d code on line 7
Yes,
Thank you very much
Great
Finaly to calculate a diff between 2 date and save it in "save data"
Create a php function date_diff with
$d1 = new DateTime( $this->get('d1') );
$d2 = new DateTime( $this->get('d2') );
$interval = $d2->diff($d1);
echo $interval->format("%a");
-------------------------------------------
And in in Data override on Update
duration:{fn:date_diff$d1=(data:campaign.end_date)&d2=(data:campaign.start_date)}