F
F
full-size2021-01-29 15:10:19
PHP
full-size, 2021-01-29 15:10:19

How to finalize the function of displaying the next month after the current one?

Hello!
There is a function to display the month 30 days from the current date:

function displaydate( $atts ) {
  $atts = shortcode_atts( array(
    'day'   => '30'     
  ), $atts );
  $plus_days = $atts['day'];
  return date_i18n('F', strtotime('+' . $plus_days . 'day'));
}
add_shortcode('show_date', 'displaydate');


Please tell me a practical solution, how to make the function display the next month after the current month, taking into account the fact that different months have a different number of days and there is a 28-day February?

Thanks to!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Zolin, 2021-01-29
@artzolin

To get the day:
date_i18n('d',strtotime('+1 month'));
Update
If you want to get the next month regardless of the current date:
date_i18n('F',strtotime('first day of +1 month'));

H
hint000, 2021-01-30
@hint000

https://www.php.net/manual/ru/datetime.formats.rel...
instead strtotime('+' . $plus_days . 'day')
write strtotime('first day of next month')and the result will be the 1st of the next month.
There is no need to add a fixed number of days (30) if the number is not important, but only the month is important.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question