Calculate remains date by custom fields date

Viewed 17

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. Suppose a deadline has been set to 01/01/2023. How I'll count days between today and this date? 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?

1 Answers

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);
Related