Jump to content

displaying when message was posted


runnerjp

Recommended Posts

<? $dbtime = $getthreads3['lastrepliedto']; 
         $dbtime=$getthreads3['showtime']; $time = date("F j, Y, g:i a", $dbtime); 


// Get current timestamp
$intTime = time();
// Calculate difference
$intDiff = $intTime - $dbtime;

// Check time
switch($intDiff)
{
      case ($intDiff < 60):
                echo "<strong>Less than a minute ago</strong>";
                break;
        case ($intDiff < 3600):
                echo "<strong>Less than an hour ago</strong>";
                break;
        case ($intDiff < 7200):
                echo "<strong>One hour ago</strong>";
			break;
        case ($intDiff < 10800):
                echo "<strong>Two hours ago</strong>";
			break;
	case ($intDiff < 86400):
                echo "<strong>Today</strong>";
			break;
	case ($intDiff < 172800):
                echo "<strong>Yesterday</strong>";
                break;
        default:
               echo $time;
}
?>

 

the code works if its posted as a thread but for some reason if the thread is replied too it just shows    default:

              echo $time;... any suggestions why?

Link to comment
https://forums.phpfreaks.com/topic/130733-displaying-when-message-was-posted/
Share on other sites

hmm yeah quite true Mchl. to be honest if i ever use a case it is for a straight statment anyway such as

 

switch($name)

{

case"tim":

break;

case "bob":

break;

}

 

i never do any sort of checking in a switch really.

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.