PHP supports various date types and its conversion.
The following php example demonstrate to add n number of days in the provided date.
For date format: yyyy-mm-dd
function addDate($date,$n)
{
$dateArray=explode('-',$date);
$addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
return date("Y-m-d", $addDate);
}
Usage of the function is as follows:
$n = 1;
$date = "2014-06-01";
echo addDate($date, $n);
Ouput is: 2014-06-02
For date format: yyyy/mm/dd
function addDate($date,$n)
{
$dateArray=explode('/',$date);
$addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
return date("Y-m-d", $addDate);
}
Usage of the function is as follows:
$n = 1;
$date = "2014/06/01";
echo addDate($date, $n);
Ouput is: 2014/06/02
The following php example demonstrate to add n number of days in the provided date.
For date format: yyyy-mm-dd
function addDate($date,$n)
{
$dateArray=explode('-',$date);
$addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
return date("Y-m-d", $addDate);
}
Usage of the function is as follows:
$n = 1;
$date = "2014-06-01";
echo addDate($date, $n);
Ouput is: 2014-06-02
For date format: yyyy/mm/dd
function addDate($date,$n)
{
$dateArray=explode('/',$date);
$addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
return date("Y-m-d", $addDate);
}
Usage of the function is as follows:
$n = 1;
$date = "2014/06/01";
echo addDate($date, $n);
Ouput is: 2014/06/02
No comments:
Post a Comment