This topic is locked
[SOLVED]

 Dates and Calculating days and changing colour of row

2/8/2020 9:59:00 AM
PHPRunner General questions
W
whiz_kid_uk author

I have Two Feilds,

DateDue

DateArrived
I want to see if the difference is more than two days and the if it is colour the row, I am doin gthis on the list page After REcord is processed.
datediff($data['DateDue'],$data['Datearrived']) as days_diff;

If days_diff > 2

$record["css"]="background:yellow;";
However I get error on the first line :
syntax error, unexpected 'as' (T_AS) in line 37

lefty 2/8/2020



I have Two Feilds,

DateDue

DateArrived
I want to see if the difference is more than two days and the if it is colour the row, I am doin gthis on the list page After REcord is processed.
datediff($data['DateDue'],$data['Datearrived']) as days_diff;

If days_diff > 2

$record["css"]="background:yellow;";
However I get error on the first line :
syntax error, unexpected 'as' (T_AS) in line 37


Try This:
$date1=$data["DateDue"];

$date2=$data["Datearrived"];

$diff=date_diff($date1,$date2);

If ($diff > 2) {

$record["css"]='background:yellow;';

} else {

}

W
whiz_kid_uk author 2/9/2020

Thanks John, Although still does not work..

$date1=$data["DateDue"];

$date2=$data["Datearrived"];

$diff=date_diff($date1,$date2);

If ($diff > 2) {

$record["css"]='background:yellow;';

} else {$record["css"]='background:Lightgreen;';

}


The Rows / Records are all green ??



Try This:
$date1=$data["DateDue"];

$date2=$data["Datearrived"];

$diff=date_diff($date1,$date2);

If ($diff > 2) {

$record["css"]='background:yellow;';

} else {

}

Admin 2/9/2020

date_diff and similar functions work with DateTime values while what you have in the $data array are strings. Before performing your calculations you need to convert string values either to DateTime objects or to number of seconds. I recommend using the second approach explained in this article: https://www.geeksforgeeks.org/how-to-calculate-the-difference-between-two-dates-in-php/

W
whiz_kid_uk author 2/10/2020

Sergey ! Thank you worked Perfectly !!

lefty 2/10/2020



Sergey ! Thank you worked Perfectly !!


Jez,

What was your result? Maybe me and others could use this also . I assume you have to use strtotime in the date fields to format the dates first.