开发者

Get month of a given date

开发者 https://www.devze.com 2023-01-11 15:38 出处:网络
Get month of a given date which is stored in a PHP time var开发者_JS百科iable in \'Y-m-d\' formatTry date_parse_from_format():

Get month of a given date which is stored in a PHP time var开发者_JS百科iable in 'Y-m-d' format


Try date_parse_from_format():

$date = "2010-08-12";
$d = date_parse_from_format("Y-m-d", $date);
echo $d["month"];


$date = "2010-10-10";
echo date("m", strtotime($date))?>


$parts = explode('-',$your_date_variable_in_php);
$month = $parts[1];


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


echo date("F", strtotime("2010-08-13"));


You can use date() and strtotime():

<?php
    $date = "2010-08-13";
    echo date("m",strtotime($date))."\n";
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号