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
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