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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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