title: PHP How to find the number of day's before the event happen compare to current date
body: <p>How to find the  number of day's before the event happen compare to current date , i having Linux time in my database i am converting the Linux to ordinary time <code>like 2012-05-28 17:25:43,</code> </p>
  
  <p>i am tried like this its not working</p>
  
  <pre><code>   $sql_sms_transactions = "SELECT MAX(`sendtime`) FROM `sms_transaction`  where customer_id='$customer_id'";
  
      $result_sms_transactions = mysql_query($sql_sms_transactions);
      while($row2=mysql_fetch_assoc($result_sms_transactions))
  {
  
      $status = $row2['MAX(`sendtime`)'];
  
      $timestamp2 = $status;
  
  
      $ptime= gmdate("Y-m-d H:i:s", $timestamp2);
  
   function time_elapsed_string($ptime)
    {
  $etime = time() - $ptime;
  
  if ($etime &lt; 1)
  {
      return '0 seconds';
  }
  
  $a = array( 12 * 30 * 24 * 60 * 60  =&gt;  'year',
              30 * 24 * 60 * 60       =&gt;  'month',
              24 * 60 * 60            =&gt;  'day',
              60 * 60                 =&gt;  'hour',
              60                      =&gt;  'minute',
              1                       =&gt;  'second'
              );
  
  foreach ($a as $secs =&gt; $str)
  {
      $d = $etime / $secs;
      if ($d &gt;= 1)
      {
          $r = round($d);
          return $r . ' ' . $str . ($r &gt; 1 ? 's' : '') . ' ago';
      }
  }
       }
  
  }
  </code></pre>
  
  <p>i want to compare this  <code>2012-05-28 17:25:43</code> with current date (today) and find out how many days before it happens i want only days,</p>
  
  <pre><code>final out put text should be like xx Days Ago
  </code></pre>
  
  <p>Does anyone have a better solution or code thanks.....</p>