简体   繁体   English

设置输出日期格式MSSQL / PHP / SQLSRV

[英]Set output date format MSSQL/PHP/SQLSRV

I'm using PHP + SQLSRV extension along with a MSSQL database (2008). 我正在使用PHP + SQLSRV扩展以及MSSQL数据库(2008年)。 When querying I was getting date objects for the date fields, by using "ReturnDatesAsStrings" parameter for sqlsrv_connect function I was able to get a string date instead of objects. 查询时,我通过使用sqlsrv_connect函数的“ ReturnDatesAsStrings”参数来获取日期字段的日期对象,因此我可以获取字符串日期而不是对象。 I was wondering if there's a similar way for setting up date formats (pass a format when establishing a connection) so I don't need format it from app's end. 我想知道是否有类似的方法来设置日期格式(在建立连接时传递格式),所以我不需要从应用程序的一端对其进行格式化。

I ran into the same problem, by any chance where you using Codeigniter's activerecord? 我遇到了同样的问题,您在哪里使用Codeigniter的activerecord?

this is how I solved it with activerecord,: 这是我用activerecord解决的方法:

// returns true on successful update
public function last_touched($user_id)
{
    // the format used in ISO 8601
    $time = date("Y-m-d"); // = "2013-06-10"

    $sql_query  = "UPDATE Users ";
    $sql_query .= "SET Modified= '{$time}' ";
    $sql_query .= "WHERE ID= '{$user_id}'";
    return $this->db->query($sql_query);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM