[英]how to get the previous 3 months with the current month in php
如何在php中获得当前月份的前3个月?
Something like this 像这样
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
This functions return unix timestamp, and can be formated with date function. 该函数返回unix时间戳,并可以用date函数格式化。
You will need to read about functions: date() , mktime() 您将需要阅读有关函数的信息: date() , mktime()
This can be done by appyling the string-to-time method of PHP 这可以通过应用PHP的字符串时间方法来完成
$lastMonth = date('m', strtotime('last month'));
$twoMonthsAgo = date('m', strtotime('-2 months'));
$threeMonthsAgo = date('m', strtotime('-3 months'));
You can read more about strtotime here: http://www.php.net/strtotime 您可以在此处阅读有关strtotime的更多信息: http ://www.php.net/strtotime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.