dtx9763 2019-01-18 10:23 采纳率: 100%
浏览 100
已采纳

从DateTime对象中分隔日期属性

Unable to separate the date property from the DateTime object. What do I do?

I have used the following code:

while( $fetch = sqlsrv_fetch_array( $stmt , SQLSRV_FETCH_ASSOC) ) {
    //echo '<pre>'; 
    print_r($fetch); exit;
    $date=$fetch['Dt_Installment_Date'];
    echo '<pre>'; print_r($date); exit;
}

The current output that I am getting is as follows:

<pre>DateTime Object
    (
        [date] => 2019-01-18 00:00:00.000000
        [timezone_type] => 3
        [timezone] => Europe/Berlin
    )

I want to get only the [date] property and nothing else.

  • 写回答

1条回答 默认 最新

  • doukun1450 2019-01-18 10:31
    关注

    That's how you can format your DateTime object and convert into a String.

    // Y : means year , m : means months , d : means days. and you can change format by seperating "/" or using same with "-"
    $result = $date->format('Y-m-d');
    
    echo $result;
    

    Output is 2019-01-18

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度