Jump to content

if statement help


eddbrett

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.