Subtracting dates, then running a DB query?

Discussion in 'PHP' started by zulubanshee, Nov 16, 2007.

  1. #1
    I plan on running a php job to create an xml feed once a week. However, I will be running the job manually, so it will not be *exactly* once a week, it will be 7 days 3 hours and 11 minutes or 6 days 22 hours and 57 minutes, you get the idea.

    I want to keep the time of the previous DB call in a flat file, then I want to database query to only return records from that time forward.

    If this is an overly simple question, kindly direct me to the proper thread.
     
    zulubanshee, Nov 16, 2007 IP
  2. MakeADifference

    MakeADifference Peon

    Messages:
    476
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not setup a cron job that runs once a week on a particular time?
     
    MakeADifference, Nov 16, 2007 IP
  3. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How about something like this?:

    $lastRun = "11/16/2007 19:03:21";
    $lastRunEpoch = strtotime($lastRun);
    $query = 'SELECT * FROM tablename WHERE timestampcolumn > (FROM_UNIXTIME(' . $lastRunEpoch . '))';
    PHP:
    Only instead of $lastRun being set here you would have it pulled from your text file. And then maybe write the current date to your text file after the query is executed for the next time the script is run.
     
    drunnells, Nov 16, 2007 IP