Link to home
Start Free TrialLog in
Avatar of Crys_Crys
Crys_Crys

asked on

PHP Date display - It's not 1969!!!

(NOTE:  I am fairly new to PHP and most explainations will most likely confuse me alot, such as ones displayed on "helpful" tutorial sites.)

Here is my current code for inputting the date of the submit botton was pushed:

mysql_select_db($mysql_dbas);

if(isset( $submit ))
{
$sql = mysql_query("INSERT INTO `blog` (`id`, `date_entered`) VALUES ('',  CURDATE( ))");
}

$query = "SELECT * FROM `blog`";
$data = mysql_query($query);
for($i=0;$i<mysql_num_rows($data);$i++) {
    $posts[$i]['date_entered'] = mysql_result($data, $i, 'date_entered');
   }

?>
<?PHP
if(count($posts)<7) {
$show_posts = count($posts);
}

for($i=0;$i<$show_posts;$i++) {
?>

<table align="center" border="0" width="80%">
      <tr>
            <td>

            <div align="right"><? echo $posts[$i]['date_entered'] ?></div>


eh<br>
<?php } ?>

<form method="post" action="login.php">
<input name="date_entered" type="hidden">
<input value="submit" name="submit" type="submit">
</form>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Ok, so here's a short history of my issue:

1.  Currently, the time will show up as, using today as an example, 2005-08-29.
2.  I've had people try to help me already, and suggested I use TIME() instead of CURDATE() and format the date where it's outputted now as DATE('l, F j, Y', $posts[$i]['date_entered']), but that only gives me: Wednesday, December 31, 1969.  It's the same if I just keep using CURDATE().
3.  http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html  DID NOT help me.  It only confused me more.
4.  PHPBuilder.com and PHP.net have also just confused me more.
5.  I have tried making date_entered a varchar, date, datetime, int, and timestamp, as well as trying to output the date as unix_timestamp.  Those all give the same output.
6. I am running a while loop because this will be used for other scripts I have.  Most 'fetch' statements only give me loads of errors.


I have a feeling when I use DATE(), it's only reading the l,F j, Y as 0, therefore resetting the time to 1969.  I would like to display the date as, using today as an example:  Monday, August 29, 2005 if it is possible.  This seemed like a fairly simple issue at first, but

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of nouse33
nouse33

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crys_Crys
Crys_Crys

ASKER

That does work, but if I try and add values for the actual time (to see if it's getting the current time from the server clock)  it's staying at 12:08, no matter how long I wait before posting again.  So, I don't know if this is the acurrate time or what it's doing.  All the queries say 08.
Oh, and a while loop MUST remain intact so I can put more variables in later.
Alright, I just changed my variable time to DATETIME, and now it works perfectly.

Now I need to figure out how to get the current timezone (possibly from the user's timezone?)  If not, I'll be fine sticking with EST time.
curdate() just gives you the date, not the dste and time.  if you want the date and time you can just change that to now() in your insert query and it will insert the date and time.  you should make sure the date_entered field in your mysql table is of type "datetime" though.

i'm not sure what while loop you're talking about.  you didn't have one in your code but i added one.
try this...

$timestamp = strtotime(mysql_result($data, $i, 'date_entered'));
$posts[$i]['date_entered'] = date('l, F j, Y', $timestamp);
All that did was tell me it couldn't read line 2 of timestamp, and it still has the date being numbers.

The only thing I see for finding a timezone is in an array and you need to use time() to access it.  Plus nothing was available for input into a database.
Alright, nevermind.  I'll figure it out when I need the time then.

Right now I'm having an issue with everything looping since the method given to me didn't include the for loop that I need for the rest of my scripts.

$query = "SELECT * FROM $table ORDER BY count DESC";
$data = mysql_query($query);
for($i=0;$i<mysql_num_rows($data);$i++) {
      $posts[$i]['gold_current'] = mysql_result($data, $i, 'gold_current');
      $posts[$i]['gold_last'] = mysql_result($data, $i, 'gold_last');
      $posts[$i]['log_entry'] = mysql_result($data, $i, 'log_entry');

}

$entered = "SELECT UNIX_TIMESTAMP(date_entered) as time_entered FROM $table";
$data = mysql_query($entered);
$date_entered = date('l, F j, Y', $post->time_entered);

All that does is cause a repeat of all the information in the page to repeat several times to the right.