show the message time in the inbox php
Hi i am doing internal mail service application ,
i have the field called datetime in my table,
i want to show the mail datetim in the inbox view somthing like gmail inbox,
i want to show if the mail came just 10 min aga means , i want to show 10min ago,
if mail came around 2 days back means i want to show the DATE-Time ,
Thing keep in mind i maintain the DATETIME datatyoe ,
Thanks Bharanikumar
This is snippet i have...
list($date, $time) = explode(' ', $session_time);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$session_time = mktime($hour, $minute, $second, $month, $day, $year);
$time_difference = time() - $session_time ;
echo $seconds = $time_difference ;
$minutes = round($time_difference / 60 );
$hours = round($time_difference / 3600 );
$days = round($time_difference / 86400 );
$weeks = round($time_difference / 604800 );
$months = round($time_difference / 2419200 );
$years开发者_StackOverflow = round($time_difference / 29030400 );
if($days>2){
echo date("d-m-Y G:i",$session_time);
}else
// Seconds
if($seconds <= 60)
{
echo "test$seconds seconds ago";
}
//Minutes
else if($minutes <=60)
{
if($minutes==1)
{
echo "1 minute ago";
}
else
{
echo "$minutes minutes ago";
}
}
//Hours
else if($hours <=24)
{
if($hours==1)
{
echo "1 hour ago";
}
else
{
echo "$hours hours ago";
}
}
What you want it what people call Pretty Date. Here is the basic algorithm JavaScript. You should be able to easily port it to PHP.
精彩评论