I have looked all over and I can't work out why this isn't working. I am trying to compare today's date to a date I set. I want to know if the date is greater than or equal to todays date. For some reason my code isn't working and I can't figure out why. This is the code I have:
<?php
$date_now = date("d-m-Y");
if (($date_now >= date("01-12-2020"))) { ?>
greater than 1st
<?php } else { ?>
not greater than
<?php } ?>
I am sure it is something simple but I have looked all over and I can't work out what I am missing.
You could try like this with \\strtotime()
native php function :
<?php
$date_now = date("d-m-Y");
// now compare date as timestamp
// 1606780800 (1st december 2020) is greater than 1606176000 (24th november 2020)
if (\strtotime($date_now) >= \strtotime(date("01-12-2020"))) {
echo 'greater than 1st';
} else {
echo 'not greater than';
}
\\strtotime
give you the ability to retrieve timestamp from an date (as text or locale notation).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.