【问题标题】:Get month from mssql DateTime Object with php使用 php 从 mssql DateTime 对象获取月份
【发布时间】:2014-02-21 21:43:26
【问题描述】:

当我打印数组时,我得到了这个

[CreatedDate] => DateTime Object ( [date] => 2013-03-20 00:00:00 [timezone_type] => 3 [timezone] => America/Denver )

我正在尝试从日期中提取月份,到目前为止还没有运气。一直在组合下面的代码并得到一个返回日期,但它是 1969 年 12 月 31 日,这不在我的数据库中

$month = date("m",($row['CreatedDate']));
$month = date("m",($row['CreatedDate.date']));
$month = date("m",($row['date']));

【问题讨论】:

  • 你已经接近了....谷歌“PHP mktime”。
  • 创建这个对象的代码是什么?正如下面的答案所示,这可能已经是一个 PHP 日期对象。
  • 我刚刚对查询做了一个 print_r

标签: php sql-server datetime


【解决方案1】:

任何生成 DateTime 对象的东西都已经拥有你需要的东西。您只需拨打format() 即可获得月份:

echo $object->format('m');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多