SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A date detector of some sort

    What I'm in need of doing by can't get my head around is something that will check whether a download has been added or updated in the past x days.

    You've got a date the downloads been added/updated on one side. And on the other corner we've got the current date. My problem is that I haven't got the faintest clue on how to compare/relate the two.

    Help will be appreciated.
    Bardius

  2. #2
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    Orange County, Ca
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bardius - depending on the format that you have your date in, what I would do is convert the date to a timestamp and then compare it to the current timestamp.

    // this converts current date to a timestamp
    $date1 = strtotime($date1);
    // set this in seconds to however far back you want to check
    $offset = 86400;

    // time() gives you the current timestamp
    if ($date1 > (time() - $offset) {
    // a download has been done within the past x days
    // do something
    }
    else {
    // do something else
    }

    hope this gives you a starting point
    Wordpress Auto Installer
    www.webproco.com

  3. #3
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To retrieve the date that a file on the local filesystem was last modified you can use the filemtime() function. A modification of the above example would look like the following:

    PHP Code:
    /* Retrieve the last modification date for your file */
    $date1 filemtime('/path/to/your/file.ext');
    if(
    $date1) { 
       
    /* set this in seconds to however far back you want to check */
       
    $offset 86400

       
    /* time() gives you the current timestamp */
       
    if ($date1 time() - $offset) { 
          
    /* the file has been modified within the past x days so do something */
       
    } else { 
          
    /* do something else */
       
    }
    } else {
       
    /* Oops, the file was not found */

    - Marshall


Bookmarks

Posting Permissions

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