Page 1 of 1
Todays Date > the $todate = says yes, but it isn't.
Posted: Fri Sep 17, 2010 8:43 am
by simonmlewis
Code: Select all
$todate = new DateTime($row->dateto);
if ($today > $todate)
{ echo "<div style='border: 1px dotted #ff0000; padding: 2px; font-size: x=small;'>EXPIRED</div>";}
The $row->dateto here is 17th September 2010.
Today's date is 17th September 2010.
This is showing the Expired result.
And when i do:
Code: Select all
$calc = ($todate < $today);
echo "$calc";
It gives a result of 1.
It should be zero, or empty shouldn't it?
I'm trying to show EXPIRED when an entry is either past the TO DATE.
Re: Todays Date > the $todate = says yes, but it isn't.
Posted: Fri Sep 17, 2010 9:04 am
by Eran
DateTime contains the time as well as the date. If you pass in only the date, the time will be set as the beginning of the date (00:00:00) - so this comparison will almost always fail for the current date.
Re: Todays Date > the $todate = says yes, but it isn't.
Posted: Fri Sep 17, 2010 9:16 am
by simonmlewis
Code: Select all
$today = (date('Y-m-d'));
$todaydate = strtotime($today);
$fromdate = strtotime($row->datefrom);
$todate = strtotime($row->dateto);
if ($todaydate > $todate)
Bingo - thanks a lot.