Answer the question
In order to leave comments, you need to log in
How to solve such problem with time manipulation in php?
Good day. There is such a task:
We accept orders every week until Friday (14.00), and issue ready-made orders every Monday at 11.00, those in three days.
That is why, as soon as the acceptance of orders ends on Friday at 14.00, the date on the site automatically changes to the next date for the issuance of orders.
Example: The end date for receiving an order is 12.05.17 at 14.00, the order is issued on 15.05.17 at 11.00, if the client entered the site on 14.01 and made an order on 12.05.17, then he will see that his order will be ready on 05.22.17. Those in a week.
I can't think of anything to get away from. Thought to do checks for every day of the week. Maybe there is a method to get Friday of the current week? Please help me.
Answer the question
In order to leave comments, you need to log in
$dateTime = new \DateTime('this friday');
echo $dateTime->format('Y-m-d');
$now = new \DateTime();
$friday = new \DateTime('this friday');
$result = new \DateTime('next monday');
if ($now->format('Y-m-d') == $friday->format('Y-m-d') &&
$now->format('H:i:s') >= '14:00:00') {
$result->add(new \DateInterval('P1W'));
} elseif ($friday < $now) {
$result->add(new \DateInterval('P1W'));
}
echo $result->format('Y-m-d');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question