Jump to content

Timestamp display incorrect


webguync

Recommended Posts

Anyone know why this timestamp would display as December 31, 1969 7:00:00pm

 

In the PHP I have

 

echo "<tr><td class='timestamp'>Login Time: " . date('F j, Y g:i:sa', strtotime($row["login_timestamp"])) . "</td></tr>";

 

and the MySQL timestamp looks like this.

 

2010-06-21 16:17:27

 

the field name is login_timestamp set to type datetime with default of 0000-00-00 00:00:00

Link to comment
Share on other sites

I personally find it helpful to do something like this @ the bottom of my index.php file.

 

echo "<pre>SESSION:";
print_r($_SESSION);
echo "<br>DATA:";
print_r($data);
echo "<br>POST:";
print_r($_POST);
echo "</pre>";

 

i just have to make sure that $data is always the result of my mysql_query so that i always have $data being output in the bottom of my page.  Works wonders when debugging.

Link to comment
Share on other sites

yes, the field name is being spelled correctly. Here is the code (I'll go ahead and display all of it, sorry if it is too much). The field in question is login_timestamp and it is in the Editor_Candidates table.

 

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
$conn = mysql_connect("localhost","uname","pw");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
  
if (!mysql_select_db("DBName")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT Responses.editor_name,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10,Answer11,Answer12,Responses.submit_timestamp,Editor_Candidates.login_timestamp,
TIMESTAMPDIFF(SECOND,submit_timestamp,login_timestamp) as cTime
FROM Responses
LEFT JOIN Editor_Candidates
USING (user_id) ";
       

$result = mysql_query($sql);



if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}


while ($row = mysql_fetch_assoc($result)) {
   echo "<tr><td class='name'>{$row['editor_name']}</td></tr>";
echo "<tr><td class='section'><strong>Section 1</strong></td></tr>";
   
   for ($i =1;$i<9;++$i) {
echo "<tr><td><p>{$row['Answer'.$i]}</p></td></tr>";
  }
echo "<tr><td class='section'><strong>Section 2</strong></td></tr>";

echo "<tr><td><p>{$row['Answer10']}</p></td></tr>";
echo "<tr><td class='section'><strong>Section 3</strong></td></tr>";

echo "<tr><td><p>{$row['Answer11']}</p></td></tr>";
echo "<tr><td class='section'><strong>Section 4</strong></td></tr>";

echo "<tr><td><p>{$row['Answer12']}</p></td></tr>";
echo "<tr><td class='section'><strong>Time:</strong></td></tr>";
var_dump($row["login_timestamp"]);
echo "<tr><td class='timestamp'>Login Time: " . date('F j, Y g:i:sa', strtotime($row['login_timestamp'])) . "</td></tr>";
echo "<tr><td class='timestamp'>Submit Time: " . date('F j, Y g:i:sa', strtotime($row['submit_timestamp'])) . "</td></tr>";
$formatted_completion_time = formatTime($row['cTime']);
  echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>\n";
  echo $formatted_completion_time;
  echo "</td></tr>";


}
mysql_free_result($result);



?>

Link to comment
Share on other sites

okay so right before you free result, put in:

 

echo "<pre>";

print_r($row);

echo "</pre>";

 

and use that for debugging..  find where your timestamp is, and make sure that it is showing what it should and that it is infact located at $row['timestamp']

Link to comment
Share on other sites

As an aside, I usually find it easier to select the timestamp with MySQL's DATE_FORMAT() function in the query string.

 

SELECT DATE_FORMAT( field_name, '%c/%e/%Y, at $h:%i, %p' ) AS date, then you would access it through the array index $row['date']. (Should return "M/D/YYYY at H:MM, AM/PM")

 

MySQL manual page for the function is HERE.

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.