DDC-782: method get and set don't work for the property datetime with sql server 2008 #962

Closed
opened 2026-01-22 12:57:25 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 1, 2010).

Jira issue originally created by user minxuan.guo:

after executing ".... convert-mapping --from-database annotation ..." with SQL server 2008, for each column which type is "datetime", doctrine 2 create a property with type="datetime"
this is ok.

BUT, the method *get* and set of these properties ( type="datetime" ) don't work.
the method "get" return 'false'
the method "set" : Fatal error: Call to a member function format() on a non-object in ......\Doctrine\DBAL\Types\DateTimeType.php on line 46

NOTE: if we replace type="datetime"* by *type="string", we can use the data like a string,

Originally created by @doctrinebot on GitHub (Sep 1, 2010). Jira issue originally created by user minxuan.guo: after executing ".... convert-mapping --from-database annotation ..." with SQL server 2008, for each column which type is "datetime", doctrine 2 create a property with type="datetime" this is ok. BUT, the method **get\* and *set** of these properties ( type="datetime" ) don't work. the method "get" return 'false' the method "set" : Fatal error: Call to a member function format() on a non-object in ......\Doctrine\DBAL\Types\DateTimeType.php on line 46 NOTE: if we replace **type="datetime"\* by *type="string"**, we can use the data like a string,
admin added the Bug label 2026-01-22 12:57:25 +01:00
admin closed this issue 2026-01-22 12:57:25 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2010):

Comment created by @beberlei:

Can you show me what the exact value of the data looks like when returned from the statement cursor? i.e. for mysql it would be something like "2010-01-04 10:10:10" for postgres its "2010-01-04 10:10:10.00000" and so on.

@doctrinebot commented on GitHub (Sep 1, 2010): Comment created by @beberlei: Can you show me what the exact value of the data looks like when returned from the statement cursor? i.e. for mysql it would be something like "2010-01-04 10:10:10" for postgres its "2010-01-04 10:10:10.00000" and so on.
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2010):

Comment created by minxuan.guo:

when I "select dateXXXX from xxxx", I'll get something like

1987-02-17 00:00:00.000

@doctrinebot commented on GitHub (Sep 1, 2010): Comment created by minxuan.guo: when I "select dateXXXX from xxxx", I'll get something like 1987-02-17 00:00:00.000
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2010):

Comment created by @beberlei:

strange, MS SQL Platform defines the default date format as Y-m-d H:i:s.u

@doctrinebot commented on GitHub (Sep 1, 2010): Comment created by @beberlei: strange, MS SQL Platform defines the default date format as Y-m-d H:i:s.u
Author
Owner

@doctrinebot commented on GitHub (Sep 2, 2010):

Comment created by minxuan.guo:

Y-m-d H:i:s.{color:red}u{color}
ok, and is there any document talk about the {color:red}u{color},

I find only this

http://msdn.microsoft.com/en-us/library/ms187819.aspx

time 12:35:29. 1234567
date 2007-05-08
smalldatetime 2007-05-08 12:35:00
datetime {color:red}2007-05-08 12:35:29.123{color}
datetime2 2007-05-08 12:35:29. 1234567
datetimeoffset 2007-05-08 12:35:29.1234567 +12:15

@doctrinebot commented on GitHub (Sep 2, 2010): Comment created by minxuan.guo: **Y-m-d H:i:s.{color:red}u{color}** ok, and is there any document talk about the **{color:red}u{color}**, I find only this http://msdn.microsoft.com/en-us/library/ms187819.aspx **time** 12:35:29. 1234567 **date** 2007-05-08 **smalldatetime** 2007-05-08 12:35:00 **datetime** {color:red}2007-05-08 12:35:29.123{color} **datetime2** 2007-05-08 12:35:29. 1234567 **datetimeoffset** 2007-05-08 12:35:29.1234567 +12:15
Author
Owner

@doctrinebot commented on GitHub (Sep 2, 2010):

Comment created by the_angry_angel:

Sorry for butting in, but this had me the other day.

Minxuan if you check out line 392 of Doctrine/DBAL/Platform/MsSqlPlatform.php you'll notice that Doctrine expects DATETIME2(6) to be used for datetime fields in the database :)

When you run the convert mapping it doesn't currently check and throw a warning if you're just using DATETIME :)

@doctrinebot commented on GitHub (Sep 2, 2010): Comment created by the_angry_angel: Sorry for butting in, but this had me the other day. Minxuan if you check out line 392 of Doctrine/DBAL/Platform/MsSqlPlatform.php you'll notice that Doctrine expects DATETIME2(6) to be used for datetime fields in the database :) When you run the convert mapping it doesn't currently check and throw a warning if you're just using DATETIME :)
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2010):

Comment created by @beberlei:

This should be fixed already.

@doctrinebot commented on GitHub (Dec 28, 2010): Comment created by @beberlei: This should be fixed already.
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 28, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#962