I need help with my script that is comparing current date with date that is entered in database, the thing that I wont to do is get alert message when the date from database pass the current date, and alert if the date from database is near the current date. The problem with my code comes when the month is different. Script works when comparing current day and day from database date, but when the month is different for example 02.05.2012 and 28.04.2012 the script is acting as if the 28.04.2012 is yet to come, he is not taking the month in consideration. I hope the question is clear. Here is the coding so far. Any ideas?
$vrjedi_do_osobna = $row['vrjedi_do_osobna'];
$current_date = date('d.m.Y');
$query = mysql_query("SELECT * from albums where vrjedi_do_osobna = '$current_date'
AND $id = 'userid'");
$ime = $row['dosjename'];
$prezime = $row['dosje_prezime'];
$diff = abs(strtotime($current_date) - strtotime($vrjedi_do_osobna));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
if($current_date < $vrjedi_do_osobna && $days < 10 && $days > 0 && $years < 1 && $months < 1)
{
echo"<font face='gregorian' size='2'>";
printf(" <img src='slike_izgled/pj_sat.png' width='20' height='30'/> Osobna iskaznica radnika $ime $prezime ističe za %d dana\n", $days);
echo"</font><br>";
}
if ($vrjedi_do_osobna <= $current_date)
{
echo "
<img src='slike_izgled/usklik.gif' width='25' height='25'> <font face='gregorian' size='2'>Osobna iskaznica radnika $ime $prezime-a je istekla!</font> <a href='viewdosje.php?album=".$row['ideo']."'>Pregled dosjea</a><br>
";
// Do something
}
You could store in a variable
strtotime($current_date) - strtotime($vrjedi_do_osobna) and use it in the IFs by comparing it to 0 to see if the current date passed or not.