Jump to content

Time only displaying as December 31, 1969, 4:00 pm?


ffxpwns

Recommended Posts

I think its a problem connecting with mySQL, because no matter what I put in the "Date" category, it comes up as Dec 31.  Here's the snippet in question for the newArticle.php, and the corresponding snippet for the homepage layout.  If I could somehow put a  "$today = date("F j, Y, g:i a");"  at the top and replace that stuff with $today, please let me know!  The column is called publicationDate, and its a VARCHAR with 30 length.  And I'm 100% I'm connected to the DB itself, because articles will post correctly and they appear on both the webpage and their various rows.  The only one thats not working is publicationDate.

The 'write' part in newArticle.php

 

 <li>
            <label for="publicationDate">Publication Date</label>
            <input type="date" name="publicationDate" id="publicationDate" placeholder="MM-DD-YYYY, hh:mm" required maxlength="30" value="<?php 
		echo $results['article']->publicationDate? date("F-j-Y-g:i a", $results['article']->publicationDate ) : ""  ?>" />
          </li>

 

The 'read' part in the homepage

<td><?php echo date("F j, Y, g:i a", $article->publicationDate)?></td>

The "1969 error" (as I call it) happens when you give date() something that isn't a Unix timestamp, or when you give strtotime() something that it can't parse as a date string.

 

If you want to reformat the date string and you can't store it as a timestamp to begin with, run it through strtotime() first.

date("format", strtotime($date_string))

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.