View Full Version : Resolved Date/time stored and retrieved from a text db file always 12-31-1969

03-07-2009, 07:27 PM
I've found some threads with similar issues but I couldn't figure out how to resolve it in my mailing list app. I just read that the methodology here is that the written date is supposed to be the amount of seconds since January 1 1970...interesting way to store it! lol

Here's where it's written to the text file:

// Writes a new item to the file
function writeitem($f, $addr) {
global $nextindex, $fsize;
// This has to be padded because we are editing the top of the file
fwrite($f, str_pad($nextindex+1, LIN, '0', STR_PAD_LEFT));
fseek($f, $fsize);
$newdata = $nextindex.SP.$addr.SP.time().SP.$_SERVER['REMOTE_ADDR'].NL;
fwrite($f, $newdata);
$fsize += strlen($newdata);
changecount($f, 1);
return true;

Here's where it's displayed on the web:

function cmp($a, $b) {
return strcmp($b['tme'], $a['tme']);
usort($email, "cmp");
$perpg = 20;
$pgs = ceil(count($email)/$perpg);
$pg = $_GET['pg'];

<? echo date('m-d-Y', $subs[$i]['tme'])?>&nbsp;&nbsp;<? echo date('g:i A', $subs[$i]['tme'])?>

03-07-2009, 10:52 PM
It's hard to figure out what in the world your code is doing, especially since you are passing back and forth globals. However, I can give you what what will hopefully be a useful piece of information:

print date('m-d-Y', 0);
# prints '12-31-1969'

as you said, php times are counted as seconds since January 1, 1970 (the unix epoch, all unix/linux machines keep time this way). So if you pass a time of '0' to date, it will print out December 31, 1969. So the reason why your code is printing this out is because it thinks the time is zero. So, either your code to write out the time isn't working, or you are not properly fetching the time. It should be simple enough to check the file contents to make sure the date is there, and if it is to add some print statements to the part that reads in the database file to make sure everything is actually loading properly.

03-07-2009, 11:30 PM
UGH!!! The problem was a misnamed variable. There was a line of code (which I forgot to include in my original post):

$email[$i]['tme'] = $lines[0];

Thus, changing the echo statement from this:

<? echo date('m-d-Y', $subs[$i]['tme'])?>

To the following worked. I need sleep.

<? echo date('m-d-Y', $email[$i]['tme'])?>