I'm working with PHP and SQLSRV.
I need to insert a date into a field of type Datetime
and I can not do it at all. At least not the ways I have found in Internet searches.
The last one I tried was this, because they said it worked:
if(isset($_POST['cadastrar'])){
$dataInicio = $_POST['data'];
$dataHoje = date("Y-m-d");
$dataInicio['data'] = $_POST['data'];
$data = DateTime::createFromFormat('l, j F, Y', $dataInicio['data']);
$data = $data->format('Y-m-d H:i:s');
$dataHoje['data'] = $_POST['data'];
$dataHj = DateTime::createFromFormat('l, j F, Y', $dataHoje['data']);
$dataHj = $dataHj->format('Y-m-d H:i:s');
$sql = "INSERT INTO [RDO].[dbo].[CAD_FUN] (DATA, DATAINI) VALUES (?,?)";
$params = array($data, $data);
However, when you click on register, the following warning appears:
Fatal error: Call to a member function format () on a non-object