dg / dibi

Dibi - smart database abstraction layer
https://dibiphp.com
Other
487 stars 136 forks source link

MsSQL returned value of datetime column can not be normalized, no chance to get DateTime #180

Closed matak closed 8 years ago

matak commented 9 years ago

if you select datetime column mssql returns

something like this

Jun 17 2015 12:00:00:000AM

but normalize function will not create DateTime object bcs

https://github.com/dg/dibi/blob/master/dibi/libs/DibiResult.php#L508

this is not true

(int) $value !== 0

if you want to get from mssql date format like this 2015-06-17 00:00:00

you need to use this

CONVERT(VARCHAR(19), d.Datum, 120) as Datum,

in your query, but this will be detected like string not datetime so again DateTime object will not be created

milo commented 9 years ago

AFAIK, default date format depends on session language. You can change the session language or maybe set the DATEFORMAT.

bckp commented 8 years ago

This is issue of MsSQL, not Dibi by my opinion. To get DateTime object in PHP from DIBI, you should use CONVERT in QUERY and then setType method of Dibi (or asDateTime on Dibi\Row)

$query->setType('column', \Dibi::DATETIME)->fetch();

$row->asDateTime('column')

See this https://api.dibiphp.com/3.0.1/source-Dibi.Row.php.html#31-47 https://api.dibiphp.com/3.0.1/source-Dibi.Result.php.html#537-547

bckp commented 8 years ago

@dg close please, this is not bug

dg commented 8 years ago

Probably condition can be improved to accept this format.

bckp commented 8 years ago

@dg Thanks 👍