richiec Posted January 27, 2008 Share Posted January 27, 2008 if(strtotime('now') > strtotime("{$date}")) { echo "something when strtotime > than just the date"; } elseif(strtotime('now') > strtotime("{$date $time}")) { echo "something when strtotime > date and time"; } else { echo "defult for if strtotime < now"; } Can anyone see what is wrong with this? I am guessing it is getting confused because if strtotime > date it echos something but if strtotime > date and time it echos something else... any ideas? =\ Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/ Share on other sites More sharing options...
marcus Posted January 27, 2008 Share Posted January 27, 2008 try <?php if(strtotime('now') > strtotime("{$date}")) { echo "something when strtotime > than just the date"; } elseif(strtotime('now') > strtotime($date . $time)) { echo "something when strtotime > date and time"; } else { echo "defult for if strtotime < now"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450583 Share on other sites More sharing options...
richiec Posted January 27, 2008 Author Share Posted January 27, 2008 ok i changed it to that and it got rid of the unexpected elseif error now it echos the first one for strtotime > $date even when strtotime > $date . $time any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450599 Share on other sites More sharing options...
kenrbnsn Posted January 27, 2008 Share Posted January 27, 2008 Try: <?php $now = time(); echo 'now = ' . $now . '<br>'; echo 'date = ' . $date . '<br>'; echo 'time = ' . $time . '<br>'; switch (true) { case ($now > strtotime($date)): echo "something when strtotime > than just the date"; break; case (strtotime('now') > strtotime($date . ' ' . $time)): echo "something when strtotime > date and time"; break; default: echo "default for if strtotime < now"; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450604 Share on other sites More sharing options...
richiec Posted January 27, 2008 Author Share Posted January 27, 2008 just tried that thanks for the idea but sadly it still gave same problem it echos the one i have for if strtotime > date even when strtotime > date and time Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450609 Share on other sites More sharing options...
kenrbnsn Posted January 27, 2008 Share Posted January 27, 2008 Well, the first comparison is satisfied so, it stops looking. Switch the order of the checks: <?php $now = time(); echo 'now = ' . $now . '<br>'; echo 'date = ' . $date . '<br>'; echo 'time = ' . $time . '<br>'; switch (true) { case (strtotime('now') > strtotime($date . ' ' . $time)): echo "something when strtotime > date and time"; break; case ($now > strtotime($date)): echo "something when strtotime > than just the date"; break; default: echo "default for if strtotime < now"; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450624 Share on other sites More sharing options...
richiec Posted January 27, 2008 Author Share Posted January 27, 2008 i did that, and the date time and defult both work but now strtotime($date) doesnt work o_O Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-450635 Share on other sites More sharing options...
richiec Posted January 29, 2008 Author Share Posted January 29, 2008 bumping sorry, but i still cant get this to work right so im going to post the whole secton of code so you can maybe see more of what i am trying to do... <?php $now = putenv("TZ=America/New_York"); $currentdate = date('n-j-Y'); $datentime = date('n-j-Y',strtotime('now')); $name = mysql_result($result,$i,"name"); $date = mysql_result($result,$i,"date"); $time =mysql_result($result,$i,"time"); $respawn =mysql_result($result,$i,"respawn"); $image =mysql_result($result,$i,"image"); $image2 =mysql_result($result,$i,"image2"); $image3 =mysql_result($result,$i,"image3"); $update =mysql_result($result,$i,"update"); switch (true) { case ($date > $currentdate): echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#FF0000\'>Not Due Yet</font><br><br><font color=\'#FFFFFF\'>Due On $date <br> (Day-Month-Year)<br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image2\" alt=\"\" width=\"75\" height=\"75\">"; break; case ($now > $datentime): echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#00FF33\'><b>Due Now!</b></font><br><br><font color=\'#FFFFFF\'>Started on $date <br> (Day-Month-Year)<br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image\" alt=\"\" width=\"75\" height=\"75\">"; break; default: echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#FFFF00\'><font size=\'2\'>Due Today!</font></font><font color=\'#FFFFFF\'><br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image3\" alt=\"\" width=\"75\" height=\"75\">"; } ?> Ok what it is doing, the defult seems to work and $date > $currentdate seems to work however... when $now > $datentime it still displays the defult.. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/88068-solved-elseif/#findComment-452335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.