Find next and previous date from current date PHP
Posted by navaneeth on Nov 8, 2012 in Php | No comments yet
I found an interesting new way to find a future or past day, month, or year using PHP.To recaps we can find next and previous date from current date PHP
Here are few examples
//TODAY'S DATE $today= date("Y-m-d"); //NEXT MONTH FROM FIRST OF THIS MONTH $next= date("Y-m-d",strtotime('+1 months', strtotime(date('Y-m-01', strtotime($today))))); //PREV MONTH FROM FIRST OF THIS MONTH $next= date("Y-m-d",strtotime('-1 months', strtotime(date('Y-m-01', strtotime($today))))); //GET NEXT 10 DAYS FROM TODAY $next= date("Y-m-d",strtotime('+10 days', strtotime($today))); //REMOVE THE RECORD 1 YEAR FROM TODAY $next= date("Y-m-d",strtotime('+1 years', strtotime($today)));
It is much easier than using a timestamp and mktime() to calculate a new date. By this we can find next and previous date from current date PHP
Leave a Reply