I’m working with dates in php and I’m a little stumped
This is my code:
$day = 'Thursday';
$i = 0;
$o_date = new DateTime("2012-09-12 20:56:43 +18 hours");
$date = date_format($o_date, 'l');
$full = date_format($o_date, 'd-m-Y');
if($day!=$date) {
$date = new DateTime($date . " +1 days");
$i++;
}
$order_day = new DateTime($full . " +".$i." days");$order_day = date_format($order_day, 'D, d M');
return $order_day;
This is what I want it to do:
1) I’ve got a day in string format (eg. Thursday)
2) I’ve got an order date (eg. 2012-09-12 20:56:43)
I want to get that date and turn the day into a string (eg date_format($o_date, 'l'); so that will return Wednesday, I then want to count how many days until the next Thursday after the order date, which I’ve built an if loop for. I then want to get the original date and add the amount of days the $i has accumulated, then return the date in day format (eg. Thursday, 13 September, but for some reason my code isn’t working. Can someone see what I’ve done wrong here?
Instead of a loop, why don’t you use the numeric day and calculate: