获取以“Ymd”格式存储在 PHP 时间变量中的给定日期的月份
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];
http://php.net/manual/en/function.date.php
use this link . I think your problem is solved for any date format.
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";
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.