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>';
?>

Link to comment
Share on other sites

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! =\

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.