How I get the current and next month dates in PHP

 If you want to have the next month, I suggest you to use the current year and month but keep using the 1st.

Current Date 

$today = $today = date("Y-m-d"); 

Next Month Date

$date = date("Y-m-01");

$newdate = strtotime ( '+1 month' , strtotime ( $date ) ) ;

This way, you will be able to get the month and year of the next month without having a month skipped.

One month from today

$date = date('Y-m-d', strtotime('+1 month'));


One month from a specific date

$date = date('Y-m-d', strtotime('+1 month', strtotime('2015-01-01')));

No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...