Jump to content

calculating and displaying date


sofia403

Recommended Posts

Hi, im trying to calculate and display a time elapsed from known date in db. however im having trouble displaying it. other values display no problem, just cant calculate and display date on the fly. does anyone see a problem with my query? thank you.

 

<?php
include('config.php');
$uname=$_SESSION['username'];
if($_SESSION['username']){
$sql="SELECT country, nationality, passportDate FROM country WHERE uname='$uname'";
$result = mysql_query($sql) or die(mysql_error());
$passportDate _ts = strtotime($row['passportDate ']);
$passportDate _str = date("M-d-Y", $passportDate _ts);
$TotalTime = floor((time() - $passportDate _ts)/(60*60*24)) . ' days'; 

while($row=mysql_fetch_array($result))  {

echo "<table border='0'>
  <tr>
  <th>Nationality</font></th>
  <th>Country</font></th>
  <th>Passport Seent Date</font></th>
  <th>Time Elapsed</font></th>
  </tr>";

  echo "<tr>";
  echo "<td>" . $row['nationality']."</td>";
  echo "<td>" . $row['country'] . "</td>";
  echo "<td>" . $row['passportDate '] . "</td>";
  echo "<td>" . ('$TotalTime') . "</td>"; 
  echo "</tr>";
  }
  echo "</table>"; 
  }
?>

Link to comment
Share on other sites

You have spaces in so many places you shouldn't.

 

You can use MySQL to perform that calculation.

 

SELECT `country`, `nationality`, `passportDate`, DATEDIFF(NOW(), `passportDate`) as `totaltime` FROM `country` WHERE `uname`='$uname'

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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