Reputation: 817
I have a problem and I don't understand where it is : So If I do :
$end_date = date('Y-m-d H:i:s',strtotime("+ $frequency days")); --> it works
If I do :
$end = $o_user->end;
$o_user->end = date($end, strtotime("+ $frequency days")); ---> not work
I tested and the 2 dates have the format : Y-m-d H:i:s
Where is my error ? Please help me. Thx in advance
Upvotes: 0
Views: 54
Reputation: 574
Date's first param is the format, not an another date.
It should be something like this:
$o_user->end = date("Y-m-d H:i:s", strtotime($end . " +$frequency days"));
Upvotes: 2
Reputation: 1091
You can use below code
$i_frequency = 4;
$end = '2016-05-23 10:48:42';
echo "==" . date('Y-m-d', strtotime("+$i_frequency days", strtotime($end)));
OR
$i_frequency = 4;
$end = '2016-05-23 10:48:42';
echo "==" . addDate($end, $i_frequency);
function addDate($date, $day)//add days
{
$sum = strtotime(date("Y-m-d", strtotime("$date")) . " +$day days");
$dateTo = date('Y-m-d', $sum);
return $dateTo;
}
Upvotes: 0
Reputation: 843
Change to $o_user->end = date('Y-m-d H:i:s', strtotime($end, "+". $frequency. "days"));
Upvotes: 0
Reputation: 29932
Maybe you just want to do
$o_user->end->modify("+ $frequency days");
It's even more readable and compact.
BTW your error is that date()
function expect as first parameter a string (the date format)
Upvotes: 0