Issue
This Content is from Stack Overflow. Question asked by Saifullah
I’m building a website in WordPress with Advanced Custom Fields plugin. I’ve a date field tender_deadline
which is contain the deadline date formatted by d/m/y
$tender_deadline = get_field('tender_deadline');
$today = date("d/m/y");
Now I want to calculate how many days left from today. This will be automatic calculation based on the deadline date and today’s date.
How can I achieve this? Any php scripts there or any other solution for that?
Solution
Here’s an option
$tender_deadline = "20/09/2022";
$deadline = date_create_from_format('d/m/Y', $tender_deadline);
$today = new DateTime();
$interval = $deadline->diff($today);
echo ($interval->days);
This Question was asked in StackOverflow by Saifullah and Answered by IT goldman It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.