i can get current timest开发者_C百科amp with time(); How can i add him and get next month? So how can i get next month with timestamp?
I try with mktime and strtotime but none works.
Example:
$date = time();
$month = date('m', $date);
how to get next mont?
If you just add one month, you'll end up skipping months now and then. For example, what is 31th of May plus one month? Is it the last of June or is it the first of July? In PHP, strtotime will take the latter approach and give you the first day of July.
If you just want to know the month number, this is a simple approach:
$month = date('n') + 1;
if($month > 12) {
$month = $month % 12;
}
or for infinite flexibility (if you need to configure how many months to add or subtract):
$add = 1;
$month = ((date('n') - 1 + $add) % 12) + 1;
This gives you a date in next month:
$plusonemonth = date("Y-m-d",strtotime("+1 months"));
Modifying the output format to just m
gives you the next months number.
$month = date('n') % 12 + 1;
$month = date('m', strtotime('+1 months'));
精彩评论