-2
I need to update the date in the date field, type datetime, in a table, taking today’s date, for example. I’m trying to do it this way:
$dataHoje = new DateTime();
$sql = "UPDATE [RDO].[dbo].[ANALISE_CRITICA] SET
TXTOBS='$objetoExtra',
VLRECEITACONT='$receitaContrato', VLRECEITABRUTA='$receitaBrutaMarco',
VLISSQN='$percentualIssqn',
VLBASE='$baseCalculoIssqn',
VLIMPOSTTOTAL='$valorTotalImpostos',
VLCOMISSAO='$comissionamento',
VLCUSTO='$custoDireto',
VLADMLOCAL='$admLocal',
VLRISCO='$risco',
VLCUSTOFIN='$custoFinanceiro',
VLADMCENTRAL='$admCentral',
VLRESULTFIN='$resultadoFinanceiro',
VLCORRETAGENS='$corretagem',
dataAlteracao = $dataHoje
WHERE ID=$id";
$stmt = @sqlsrv_query( $conn, $sql);
However, when I try to update the system I get the following warning: "Catchable fatal error: Object of class Datetime could not be converted to string" What problem is this?
Try to pass the formatted date like this:
$dataHoje->format('Y-m-d H:i:s');
– rray
Where? Right after $dataHoje = new Datetime() or direct in sql command?
– GustavoSevero
Can you get the server’s time date or does it need to be an input via application? DBMS has functions that return server time, getdate() or sysdate() depending on column type
– jean