none
Datetime as string NOT object (PHP SQL Driver)

    Question

  • How would I get the date time to be given as a "string" not an object?

    I have no idea why on earth they made it as an object - its so inconsistent!

    Sorry, thought this forum was dedicated to the PHP SQL Driver.
    • Edited by AaronDM Saturday, August 15, 2009 8:02 PM
    • Moved by Raj Kasi - MSFT Monday, August 17, 2009 7:57 PM Moving to SQL Server Driver for PHP (From:SQL Server Data Access)
    Saturday, August 15, 2009 8:01 PM

Answers

All replies

  • With the version 1.1 of the PHP driver (http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&displaylang=en) there is a new connection option, ReturnDatesAsStrings, enabling the retrieval of datetime fields as strings. For more details, please check the online documentation at:

    http://msdn.microsoft.com/en-us/library/ee376928(SQL.90).aspx

     

    Thank you,

    Serban


    Serban Iliescu - MSFT
    Wednesday, August 19, 2009 5:30 PM
  • Dates are, in my opinion, correctly returned as PHP DateTime classes.  You can also do one of these (change parameters for different date formats):
    • In your SELECT statement, use an expression like this, where myDateTime is the date column:
    select convert(varchar(25), myDateTime, 21) as myDateTime
    • Or in PHP do this:
    if ( $dateColumn )
        $dateString = $dateColumn->format('Y-m-d H:i:s.u');

    Having the date as a class also allows you to tell PHP to format the date string to W3C standards or any other format, change the time zone, etc.
    Friday, August 21, 2009 12:51 PM
  • I find it in consistent with other databases. I'd rather have them either all return as an object or as a string. Why make things inconsistant?

    I've upgraded to 1.1 and am now using the option to force all datetime as strings, since my script supports both, PHP_MSSQL and PHP_SQLSRV
    Saturday, August 22, 2009 4:39 PM
  • Robert,

    Tvoj predlog mi je pomogao i uštedeo mi je puno truda.

    Hvala ti.

    Saturday, March 10, 2012 1:24 PM