Saturday, September 12, 2015

PHP get previous date

The following function gives the previous date of the date entered.

For date format: 2014-02-15

function prevDate($date)
  {
 $dateArray=explode('-',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]-1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014-02-15";
 
  echo prevDate($date);
 
  Ouput is: 2014-02-14
 
For date format: 2014/02/15

function prevDate($date)
  {
 $dateArray=explode('-',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]-1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014/02/15";
 
  echo prevDate($date);
 
  Ouput is: 2014/02/14

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...