start date minus end date equal to total

hi siri want to aski create start date with date/time picker and end date with date/time picker toi want to ask how to build like this :start date = 19/05/2018 (if user choose date now)
end date = 21/05/2018 (if user choose the end date)
total = 2 days (and show total, start date - end date = total)i try to add “aggregate” in field start date and end date but not workplease help,thanks before

Assume those fields are “Start_Date”, “End_Date”, and “Total”, then simply put this following code in “Row_Inserting” server event:$rsnew[“Total”] = DateDiff($rsnew[“Start_Date”], $rsnew[“End_Date”], “d”); // v2019

hello
The code does not work correctly
The Total field leaves blank
If it has a Total value before deleting it
Please solve the problem// Row Updating event
function Row_Updating($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$rsnew[“Total”] = DateDiff($rsnew[“Start_Date”], $rsnew[“End_Date”], “d”);

return TRUE;

}

Make sure the “Start_Date” and “End_Date” fields have already had the valid Date value.

Yes sureINSERT INTO share (id, Total, start_date, end_date) VALUES
(1, NULL, ‘2019-01-28’, ‘2019-01-30’),
(2, NULL, ‘2019-01-28’, ‘2019-02-06’),
(3, NULL, ‘2019-01-28’, ‘2019-01-30’),
(4, NULL, ‘2019-01-31’, ‘2019-02-14’),
(5, NULL, ‘0000-00-00’, ‘0000-00-00’),
(9, NULL, ‘2019-02-01’, ‘2019-02-08’),
(10, NULL, ‘2019-01-20’, ‘2019-01-23’),
(11, NULL, ‘2019-01-28’, ‘2019-02-01’),
(12, NULL, ‘2019-01-30’, ‘2019-03-08’),
(13, NULL, ‘2019-01-29’, ‘2019-01-31’);

Note that the field name is case-sensitive. Change this code:
$rsnew[“Total”] = DateDiff($rsnew[“Start_Date”], $rsnew[“End_Date”], “d”);to:
$rsnew[“Total”] = DateDiff($rsnew[“start_date”], $rsnew[“end_date”], “d”);

hello
Now working successfully
Thank youAnother request is possible
I want if it reaches the end of time the field(end_date) color changes to red// Row Updating event
function Row_Updating($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$rsnew[“Total”] = DateDiff($rsnew[“start_date”], $rsnew[“end_date”], “d”);
return TRUE;
}thanks

saleh wrote:
I want if it reaches the end of time the field(end_date) color changes to redUse “Row_Rendered” server event. Just refer to the demo project, see from “cars” table for your reference.

Here only combines night
I want the code gathered in days$rsnew[“Total”] = DateDiff($rsnew[“start_date”], $rsnew[“end_date”], “d”);


01/02/2019	08/02/2019 Total 7 night

Supposed to be : 01/02/2019 08/02/2019 Total 8 days
The above code is minus day
What’s the solution ?

Simply change this code:
$rsnew[“Total”] = DateDiff($rsnew[“start_date”], $rsnew[“end_date”], “d”);

to:
$rsnew[“Total”] = (DateDiff($rsnew[“start_date”], $rsnew[“end_date”], “d”) + 1);

Thank you so much
Works successfully

How can I solve this problem? of a date already registered, …
logic==
if the fecha_hora is greater than 1 day // green color

if the fecha_hora is greater than 2 days // yellow color

if the fecha_hora is greater than 3 days // color red


function Row_Rendered() {

$register = strtotime($this->fecha_hora->ViewValue);
$today = strtotime(date(“d-m-Y”));
$datedif = datediff(strtotime($today),(strtotime($register)),“d”);
//green
if ($datedif <= 1) {
$this->fecha_hora->CellAttrs[“style”] = “color:#FFFFFF; background-color:#088A08”;
//yellow
}elseif ($datedif = 2) {
$this->fecha_hora->CellAttrs[“style”] = “color:#FFFFFF; background-color:#FFFC2C”;
//red
}elseif ($datedif >= 3) {
$this->fecha_hora->CellAttrs[“style”] = “color:#FFFFFF; background-color:#FF0000”;
}
}

girllandrade wrote:

$register = strtotime($this->fecha_hora->ViewValue);
$today = strtotime(date(“d-m-Y”));
$datedif = datediff(strtotime($today),(strtotime($register)),“d”);

You did strtotime() twice.

girllandrade wrote:

$datedif = datediff(strtotime($today),(strtotime($register)),“d”);

should be:
$datedif = datediff($today, $register, “d”);

My code does not work:// Row Inserting event
function Row_Inserting($rsold, &$rsnew)
{
if ($rsnew[“fecha_fin”] < $rsnew[“fecha_inicio”]) {
// To cancel, set return value to false
$this->CancelMessage = “La fecha de llegada no puede ser menor a la de salida!!!”;
return false;
}
return true;
}

Now if it works perfect, thank you both very much for your time !!!
It was with the values changed as they said, a rookie mistake, excuse me.