Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts

    Date/time stored and retrieved from a text db file always 12-31-1969

    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:

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


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

    PHP Code:
    function cmp($a$b) {
          return 
    strcmp($b['tme'], $a['tme']);
        }
        
    usort($email"cmp");
        
    $perpg 20;
        
    $pgs ceil(count($email)/$perpg);
        
    $pg $_GET['pg']; 
    PHP Code:
    <? echo date('m-d-Y'$subs[$i]['tme'])?>&nbsp;&nbsp;<? echo date('g:i A'$subs[$i]['tme'])?>
    Last edited by Daniellez; 03-07-2009 at 11:32 PM.

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    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:

    Code:
    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.

  • Users who have thanked cmancone for this post:

    Daniellez (03-07-2009)

  • #3
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts
    UGH!!! The problem was a misnamed variable. There was a line of code (which I forgot to include in my original post):

    PHP Code:
    $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'])?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •