I am trying to add weeks in decimal values like 1.5, 2.5 to date through strtotime() function. But its not giving correct result. I am using it like:
$start_date = "2015-01-01";
$date = strtotime(date("Y-m-d", strtotime($start_date)) . " +3.5 weeks");
$date = date("Y-m-d",$date);
echo $date;
And its giving 2015-02-04 as output. When added non decimal values like:
$date = strtotime(date("Y-m-d", strtotime($start_date)) . " +3 weeks");
It gives perfect results.
Any thought on it?
$date = '2015-01-01';
$weeks = "2,3,4,4.5";
foreach(explode(",", $weeks) as $week) {
print $week."
";
$hours = $week * 24 * 7;
print $hours."
";
print date("Y-m-d", strtotime("{$date} +{$hours} hours"))."
";
}
You can use this logic, multiply your week decimal or not like 1,2,2.5,3,3.5 and multiply it by the amount of hours in a week :
$week = 2.5;
$desired = '+ '.$week*168.' hours';
$date = strtotime($desired, $start_date);
However, why playing with strings when you can just play with hours or seconds integers and doing a simple addition ?