HOME / BLOG / BLOG-POST

How to get time difference and active status in chatting system using php?

Get time difference and active status in chatting system using php

<?php

  $now_timestamp = strtotime(date('Y-m-d H:i:s'));
  $diff_timestamp = $now_timestamp - strtotime($end_time);
  if($diff_timestamp < 60){
   echo "active now";
  }
  if($diff_timestamp>=60 && $diff_timestamp<3600){
   $get_diff = $diff_timestamp/60;
   echo "active " . intval($get_diff) . "m ago";
  }
  if($diff_timestamp>=3600 && $diff_timestamp<86400){
   $get_diff = $diff_timestamp/3600;
   echo "active " . intval($get_diff) . "h ago";
  }
  if($diff_timestamp>=86400 && $diff_timestamp<(86400*30)){
   $get_diff = $diff_timestamp/86400;
   echo "active " . intval($get_diff) . "d ago";
  }
  if($diff_timestamp>=(86400*30) && $diff_timestamp<(86400*365)){
   $get_diff = ($diff_timestamp/(86400*30));
   echo "active " . intval($get_diff) . "m ago";
  }
  if($diff_timestamp>=(86400*365)){
   $get_diff = ($diff_timestamp/(86400*365));
   echo "active " . intval($get_diff) . "y ago";
  }

?>

 


about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *