Assign variable value to date field - please help

I want to assign the value of a variable to a date field at run time but it doesn’t, how could I do it, could you help me?

$fecha1=sc_date_conv({Fecha_entrega}, “aaaammdd”,“dd/mm/aaaa”);

$fecha2=sc_date($fecha1, “dd/mm/yyyy”, “+”,1, 0, 0);

{fecha_devolucion}=$fecha2;

$date="’".[xFecha2]."’";

$sql=“SELECT DATEADD(DD,”.[xDias];
$sql=$sql.",(CONVERT(datetime,".$date."))) as FECHA";

sc_lookup(ds,$sql);

{Fecha_devolucion}={ds[0][0]};

solved with sql

Thank you