Romit kumar February 2016

show calculated date in every row

Consider the table given below--

--------------------------------------
age              | date
1 day to 1 day   | 05/02/2016
1 day to 6 week  | 05/02/2016 to 17/02/2016
4 week to 10 week| 25/02/2016 to 14/04/2016

if 05/02/2016 is fixed then how to show other dates in PHP and this is dynamic means 05/02/2016 will be changed.

Answers


Rogin Thomas February 2016

You can use the function datetime in php. Try this, Datetime function

Eg:

<?php
$d1=new DateTime("2016-02-05");
$d2=new DateTime("2016-04-14");
$diff=$d2->diff($d1);
print_r( $diff ) ;

/* returns:
DateInterval Object ( 
 [y] => 0 
 [m] => 2 
 [d] => 9 
 [h] => 0 
 [i] => 0 
 [s] => 0 
 [invert] => 1 
 [days] => 69 
)
*/
?>

Can also use add date function

Eg:

<?php
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";
?>


sudhakar February 2016

function getSelectedDate($days){
        return date('Y.m.d',strtotime("$days days"));
    }

pass the days count 7 days a week 14 days two week it will give the date from current date. example oneWeekAfterDate = getSelectedDate(7);

Post Status

Asked in February 2016
Viewed 2,066 times
Voted 9
Answered 2 times

Search




Leave an answer