Convert mssql datetime object to PHP string

后端 未结 9 712
春和景丽
春和景丽 2021-02-05 12:41

I\'m grabbing some information from a database and the record is in an MSSQL DateTime format, when I return it, it shows in my array as follows:

[arrayItem] =>         


        
相关标签:
9条回答
  • 2021-02-05 13:12

    Try this. It works for me:

    $array['arrayItem']->format('Y-m-d H:i:s');
    

    Reference: http://php.net/manual/en/datetime.format.php

    0 讨论(0)
  • 2021-02-05 13:12
    echo $array['arrayItem']->format('Y-m-d H:i:s');
    
    0 讨论(0)
  • 2021-02-05 13:15

    Another solution is to loop.

    $_date = \DateTime::createFromFormat('D M d Y H:i:s e+', $the_date);
    foreach($_dateStart as $row){
       echo $row; // returns 2014-06-04 15:00
       break;     // stops at the first position
    }
    
    0 讨论(0)
  • 2021-02-05 13:16

    It is functionality and simple to use.

    You can convert date from date object instead of string here is the way how to use:

    $obj->arrayItem->format('H:i:s')
    $obj->arrayItem->format('Y-m-d')
    
    0 讨论(0)
  • 2021-02-05 13:24

    This worked for me

    date('Y-m-d', strtotime($rs->Fields('time')->value)
    

    For Adodb connection on MSSQL Server

    0 讨论(0)
  • 2021-02-05 13:25

    If you want to show data in PHP page you just copy and paste in <?php ?> code :

    $serverName = "your_sqlserver";
    $username = "your_username";
    $password = "your_password";
    $database = "your_database";
    $connectionInfo = array( "UID"=>$username, "PWD"=>$password, "Database"=>$database, "ReturnDatesAsStrings"=>true);
    $connection = sqlsrv_connect($serverName, $connectionInfo);
    
    $result = sqlsrv_query( $connection,"SELECT  * from table'");
    $msrow = sqlsrv_fetch_array($result);
    
    print_r($msrow['column_name']);
    
    0 讨论(0)
提交回复
热议问题