Jump to content

Problem with posting date from mysql database


badeand

Recommended Posts

I'm having problems posting date from my MYSQL database. The date in my database is this "2011-01-08 02:53:14" but the it only echo's "01.01.70"

 

Could someone help me figure out why?

 

Here is my code:

 

 <?php
$servername='localhost';


$dbusername='root';
$dbpassword='';


$dbname='store';



connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM henvendelser WHERE status = 'Ubehandlet' ORDER by id desc ") 
or die(mysql_error());  

echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>";
echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th>  <th>Emne</th> </tr>";
// keeps getting the next row until there are no more to get

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

    $postTime = $row['date'];
    $thisTime = time();
    $timeDiff = $thisTime-$postTime;

    if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7]
      $color = '#D1180A';
    } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14]
      $color = '#D1B30A';
    } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14]
      $color = '#08C90F';
    }

    echo '<tr style="color: '.$color.';">';

    echo '<td>'. $row['id'] .'</td>';

    echo '<td>'. date('d.m.y', $postTime) .'</td>';

    echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>';
  
    echo '<td>'. $row['Telefon'] .'</td>';

    echo '<td>'. $row['Emne'] .'</td>';

    echo '</tr>';

  }

  echo '</table>';
?>

try to echo the values you are working with...

 

    $postTime = $row['date'];
    $thisTime = time();
    $timeDiff = $thisTime-$postTime;

 

(1294453429) - (2011-01-08 02:53:14)

(1294453429=timestamp when I wrote this!  =P)

 

EDIT: sorry, had to edit, I put em in the wrong order...

and I also see the date is not stored as what you said, so do as Zurev said! =\

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.