I have two dates:
$today = date('j F Y');
$display_until = date('j F Y');
($display_until technically comes from an ACF field date selector):
I'm currently using:
<?php if($today < $display_until) : ?>
*where the magic should happen*
<?php endif; ?>
But it's not demarcating the events as expected ... can anyone point me in the right direction?
From the further explanation from your comments, you can use strtotime
function of php to convert any date-like string to timestamp, and later you can pass this timestamp to date
function to get the date back in your desired format.
Here is the code for that:
date('j F Y', strtotime('2017-05-01'));
if you want comparison, then:
if(strtotime('Jul 10, 2017') < strtotime('+10 days')) {
// Your logic
}
You can also use newer DateTime
object.
you have two solution:
convert dates to timestamp then compare them:
$today = date('j F Y');
$display_until = date('j F Y');
if (strtotim($today) < strtotime($display_until)){
//
}
use DateTime
object:
$today = new DateTime();
$diplay_until = new DateTime(); // or new DateTime()->modify('+1 month');
if ($today < $diplay_until){
// do something
}