Get month of a given date

前端 未结 6 1461
醉话见心
醉话见心 2020-12-14 19:08

Get month of a given date which is stored in a PHP time variable in \'Y-m-d\' format

相关标签:
6条回答
  • 2020-12-14 19:39

    is it really stored in PHP? Not in some database?
    month(datefield) can do it in mysql query for example

    0 讨论(0)
  • 2020-12-14 19:40
    $parts = explode('-',$your_date_variable_in_php);
    $month = $parts[1];
    
    0 讨论(0)
  • 2020-12-14 19:41

    Try date_parse_from_format():

    $date = "2010-08-12";
    $d = date_parse_from_format("Y-m-d", $date);
    echo $d["month"];
    
    0 讨论(0)
  • 2020-12-14 19:56
    $date = "2010-10-10";
    echo date("m", strtotime($date))?>
    
    0 讨论(0)
  • 2020-12-14 19:56
    echo date("F", strtotime("2010-08-13"));
    
    0 讨论(0)
  • 2020-12-14 19:59

    You can use date() and strtotime():

    <?php
        $date = "2010-08-13";
        echo date("m",strtotime($date))."\n";
    ?>
    
    0 讨论(0)
提交回复
热议问题