PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if ('15/11/2009' <= date('d/m/Y'))
{
echo 'overdue';
}
Can’t understand why the code seems to only return the correct value if only the ‘day’ is changed. If I change the month or year is doesn’t make any difference to the result.
Basically I wanted this to return ‘overdue’ if the full date is today or less than today.
Thanks for any tips
if (strtotime('15/11/2009') <= time()) {
echo 'overdue';
}
But watch strtotime and your date format: you're using a UK format (15th day of the 11th month), which may error because if it was parsed as a US format (11th day of the 15th month) it would be an invalid date
// Need to convert from European date to USA First
function tousdate($date) {
$d = explode('/', $date);
$d = "$d[2]/$d[1]/$d[0]"; // returns YYYY/MM/DD
return $d;
}
$usDate = tousdate($row_GetTotal['date_due']);
if(strtotime($usDate) <= time()) { echo ' overdue'; }
This works to some extent. I have a do loop running with this inside it and it’s giving me the error Fatal error: Cannot redeclare tousdate() If I remove the loop I get the correct result but I obviously need the loop. I can’t move the function to outside the loop (I think) as it’s needed within this code. I’m not too sure why I can’t re-declare this but will keep looking.
Thanks again