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

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料