Jump to content

Change date to X minutes ago (messages)


xoligy

Recommended Posts

Ok at the moment im working on a script and im trying to make it so when a pm is sent it says message was sent "x" seconds, minutes, hrs ago. Now i have the code (i believe i just cannot for the live of me get it to work because im stupid lol!

 

Ok here is the code for messages

<?=vDate($messages[$i]->date)?>  // this would output the time 22:30 or May 30, 2008

 

additional code

function vDate($time){

$timenow=time();

$timenow=date ("M d, Y",$timenow);

$time1=date ("M d, Y",$time);

if ($timenow==$time1){

	$time1=date ("H:i",$time);

}



return $time1;

}

 

Code im trying to replace it with but canna figure out how o.0

function getDateDiff($age){

$timet = 3600*24;
    $days=floor($age/$timet);
    $hours=floor($age/3600);
    $minutes=floor($age/60);
    $seconds=$age;
    
    if ($days>0)
        $age ="$days days ago";
    else if ($hours>0)
        $age ="$hours hr".(($hours>1)?"s":"")." ago";
    else if ($minutes>0)
        $age ="$minutes min".(($minutes>1)?"s":"")." ago";
    else
        $age ="$seconds sec".(($seconds>1)?"s":"")." ago";

return $age;
}//EOF

$pastdate = 1209358800;//April 28 2008
$datedif = time()-$pastdate;//subtract the past date from the current time

//now run the function
echo getDateDiff($datedif);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.