Row_Updating and Row_Inserting

When I add in the row_inserting event it only adds the concatenated event but not the date validation event. I tried to do it using form_validate but it gives me errors and it doesn’t do it.

function Row_Updating($rsold, &$rsnew){
	$rsnew["titulo_calendario"] = $rsnew["vehiculo_modelo"]." - ". $rsnew["vehiculo_dominio"];
    if ($rsnew["fecha_fin"] < $rsold["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;
}

ddiaz2380 wrote:

but not the date validation event.

Assume the field name is MyDate and the field type is DateTime, then simply put the following code into Row_Inserting server event:

// assign MyDate by current date time
$rsnew["MyDate"] = CurrentDateTime();

I have 2 fields: fecha_inicio y fecha_fin.
I need to validate that I cannot enter an earlier date and time in the fecha_inicio field that is entered in fecha_fin.
The row_updating event works fine:function Row_Updating($rsold, &$rsnew){
if ($rsnew[“fecha_fin”] < $rsold[“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;
}

  1. Are you sure $rsold[“fecha_inicio”] is correct? If both fields are from the new or updated record, it should be $rsnew[“fecha_inicio”].
  2. To compare dates, you should not compare them directly as string, read: https://discourse.hkvstore.com/t/start-date-minus-end-date-equal-to-total/635/1

In edit it works perfect, but not in insert. I just need to validate when adding that, fecha_fin is not less than fecha_inicio.

As arbei suggested above, try to change this code:
if ($rsnew[“fecha_fin”] < $rsold[“fecha_inicio”]) {to:
if ($rsnew[“fecha_fin”] < $rsnew[“fecha_inicio”]) {Or, you may also try:
if (strtotime($rsnew[“fecha_fin”]) < strtotime($rsnew[“fecha_inicio”])) {