How to find difference between (existing field time_stamp) and (current_time_stamp)?

‎1st insert current time into databse using time() function . after that retrive that time from data base and use there function 
<?php
$query = Select time from database;
$clk = $row[‘time_databse’]; ?>
<?php
$time_difference = time() -$clk ; 
$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 = round($time_difference / 29030400 ); 
if($seconds <= 60)
{
echo”$seconds seconds ago”; 
}
else if($minutes <=60)
{
if($minutes==1)
{
echo”one minute ago”; 
}
else
{
echo”$minutes minutes ago”; 
}
}
else if($hours <=24)
{
if($hours==1)
{
echo”one hour ago”;
}
else
{
echo”$hours hours ago”;
}
}
else if($days <=7)
{
if($days==1)
{
echo”one day ago”;
}
else
{
echo”$days days ago”;
}
}
else if($weeks <=4)
{
if($weeks==1)
{
echo”one week ago”;
}
else
{
echo”$weeks weeks ago”;
}
}
else if($months <=12)
{
if($months==1)
{
echo”one month ago”;
}
else
{
echo”$months months ago”;
}
}
else
{
if($years==1)
{
echo”one year ago”;
}
else
{
echo”$years years ago”;
}
}
?>
by:- rushijogle
  • Try this:

    $start_date = time(); // or your date.

    $end_date = strtotime("2013-01-01");

    $datediff = $end_date – $start_date;

    echo floor($datediff/(60*60*24));

  • try do a CAST or CONVERT on the field and compare

  • SELECT DATEDIFF(TIMESTAMP1, TIMESTAMP2) AS days;

  • SELECT(UNIX_TIMESTAMP("2009-08-17 10:00")-UNIX_TIMESTAMP("2009-08-17 09:00")) AS seconds

    >>> 3600

    ““““““““““““““

    SELECT((UNIX_TIMESTAMP("2009-08-17 10:00")-UNIX_TIMESTAMP("2009-08-17 09:00"))/3600) AS hours

    >>> 1.0000

    ““““““““““““““

  • Anonymous

    Here what posted last week: to any one in problem with the system date: a little note if you need to retrieve the system date in a database try to use the curdate() function with no argument such as:

    [[$fxdate is a constante set by the programmer and it can be variable such as a period of time, a month, a year.]]

    sql= select fname, lname, state, city from user_table where user_table.datecrted >'$fxdate' and user_table.datecrted < curdate(); that is this sql is retrieving record starting from a fix date untill it reach the current date. Try it and it work because I have just programmed it for the purpose of an admin @ http://www.iholla.com . If you have any problem let me know with the post

    Note: there is no argument and no format with the curdate()