[英]how to get the previous 3 months with the current month in php
如何在php中获得当前月份的前3个月?
像这样
mktime(0, 0, 0, date("m")); //it's 00:00 first day of current month
mktime(0, 0, 0, date("m")-1); //it's 00:00 first day of previous month
mktime(0, 0, 0, date("m")-2); //it's 00:00 first day 2 month before
mktime(0, 0, 0, date("m")-3); //it's 00:00 first day 3 month before
该函数返回unix时间戳,并可以用date函数格式化。
这可以通过应用PHP的字符串时间方法来完成
$lastMonth = date('m', strtotime('last month'));
$twoMonthsAgo = date('m', strtotime('-2 months'));
$threeMonthsAgo = date('m', strtotime('-3 months'));
您可以在此处阅读有关strtotime的更多信息: http ://www.php.net/strtotime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.