eddbrett Posted June 29, 2009 Share Posted June 29, 2009 Need abit of help with an IF statement. Basically I want it to compare the two times and if the difference is greater than 3 minutes change the statement from Listening now to:-' to 'Last listened to:-' $date = str_tz('jS M Y, H:i',$section['date'],$offset); //Last.fm date/time of last song played $date3 = date('jS M Y, H:i'); //current date/time if (($date) == ($date3)) { echo 'Listening now to:-'; } else { echo 'Last listened to:-'; } Thats what I have atm, but I need to allow for a gap of 3 minutes and I don't know how to do it. Thanks Link to comment https://forums.phpfreaks.com/topic/164139-if-statement-help/ Share on other sites More sharing options...
aggrav8d Posted June 29, 2009 Share Posted June 29, 2009 instead of date(), convert the values with mktime. as long as the difference is greater than 180 you've got your 3 minute difference. Link to comment https://forums.phpfreaks.com/topic/164139-if-statement-help/#findComment-865859 Share on other sites More sharing options...
MatthewJ Posted June 29, 2009 Share Posted June 29, 2009 Something like this maybe? $date = strtotime($section['date']); //Last.fm date/time of last song played $date2 = time(); //current date/time $date3 = ($date2 - $date) / 60; // Number of minutes if (($date3) < 3) { echo 'Listening now to:-'; } else { echo 'Last listened to:-'; } Link to comment https://forums.phpfreaks.com/topic/164139-if-statement-help/#findComment-865863 Share on other sites More sharing options...
aggrav8d Posted June 29, 2009 Share Posted June 29, 2009 Sure! It's slightly faster to use 180 so that he parser doesn't have to divide by 60 every time it runs this script. You could also compare to 3*60 (multiplication is always faster than division) Link to comment https://forums.phpfreaks.com/topic/164139-if-statement-help/#findComment-865873 Share on other sites More sharing options...
eddbrett Posted June 29, 2009 Author Share Posted June 29, 2009 Could you explain how you convert into mktime. Been trying, but can't seem to get it to work Link to comment https://forums.phpfreaks.com/topic/164139-if-statement-help/#findComment-865896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.