Reputation: 1
I try to insert Datetime in a MSSQL database but the column is in datetime. I know Symfony accept only datetime2, but i can't update the structure of this database but i need to update data with Symfony.
How can I do this ? My Entity is this
<?php
/**
* RendezVous
*
* @ORM\Table(name="RENDEZ_VOUS", indexes={@ORM\Index(name="IDX_292A17E650EAE44", columns={"id_utilisateur"})})
* @ORM\Entity
*/
class RendezVous
{
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_heure", type="datetime", nullable=true)
*/
private $dateHeure;
/**
* @var \Utilisateur
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\OneToOne(targetEntity="Utilisateur")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_utilisateur", referencedColumnName="id_utilisateur")
* })
*/
private $idUtilisateur;
public function getDateHeure(): ?\DateTime
{
return $this->dateHeure;
}
public function setDateHeure(?\DateTime $dateHeure): self
{
$this->dateHeure = $dateHeure;
return $this;
}
}
I try to create new DateTime() and just set the timestamp but it doesn't work because it's not compatible.
I try to use ->format('Y-m-d H:i:s') on the DateTime but it return me a string value and my entity attempt a DateTimeInterface.
I try to declare my column as a string column (in my sql table this is a datetime) to use the ->format() and insert with a string but it doesn't work because my sql table attempt a DateTime value
Upvotes: 0
Views: 282