Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-102

SQLSRV PDO doesn't support DateTime as a PHP Object

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1.3
    • Component/s: Drivers
    • Labels:
      None
    • Environment:
      Windows 7, Microsoft SQL Server 2008, PHP SqlSrv Driver 2.0, PHP 5.3.6

      Description

      I have created an entity with has a datetime column

      Entity.php
          /**
           * @orm:Column(name="deleteAt", type="datetime")
           */
          protected $deletedAt;
      
          /**
           * Get DeletedAt
           * @return	\DateTime	
           */
          public function getDeletedAt() {
          	return $this->deletedAt;
          }
          
          /**
           * Set DeletedAt
           * @param	\DateTime		$deletedAt
           */
          public function setDeletedAt(\DateTime $deletedAt) {
              $this->deletedAt = $deletedAt;
          }
      

      This should work, however I get this error when trying to set a "deleteAt" date

      $this->setDeletedAt(new \DateTime());
      
      SQLSTATE[22007]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.
      

      This should work afaik.

        Activity

        Hide
        Marco Pivetta added a comment -

        Michał Banaś this actually works with the current implementation of the schema tools. Consider implementing additional formats a custom DBAL type instead.

        Show
        Marco Pivetta added a comment - Michał Banaś this actually works with the current implementation of the schema tools. Consider implementing additional formats a custom DBAL type instead.
        Hide
        Michał Banaś added a comment -

        Why is it close ? After one day of waiting for response?
        Problem is not solved. It exist on ether datetime and datetime2 TSQL types.
        And it is easy to check if you have sqlserver databes.
        PLease repoen this issue.

        Show
        Michał Banaś added a comment - Why is it close ? After one day of waiting for response? Problem is not solved. It exist on ether datetime and datetime2 TSQL types. And it is easy to check if you have sqlserver databes. PLease repoen this issue.
        Hide
        Guilherme Blanco added a comment -

        Closing since no response was given.

        Show
        Guilherme Blanco added a comment - Closing since no response was given.
        Hide
        Guilherme Blanco added a comment -

        Is this issue still valid with new implementation of ParameterTypeInferer in ORM?

        It seems it solved this issue.

        Show
        Guilherme Blanco added a comment - Is this issue still valid with new implementation of ParameterTypeInferer in ORM? It seems it solved this issue.
        Hide
        Aaron DM added a comment - - edited

        https://gist.github.com/6b2a8b53ece6e75abf20

        The code there works (its not fully complete, but I tested the statements with the same Entity and etc and I am unable to successfully query the database).

        Looks like it doesn't work even for a simple select. However if I do retrieve an entry, the getCreatedAt() does return a DateTime object correctly.

        Show
        Aaron DM added a comment - - edited https://gist.github.com/6b2a8b53ece6e75abf20 The code there works (its not fully complete, but I tested the statements with the same Entity and etc and I am unable to successfully query the database). Looks like it doesn't work even for a simple select. However if I do retrieve an entry, the getCreatedAt() does return a DateTime object correctly.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Aaron DM
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: