SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Switzerland
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how to calculate with dates?

    Help! I want a script to do something if a date (stored in a mysql-db) older than 40 days from today and something else if it is newer than 40 days from today ...

    $date_today = ?????; // HOW CAN I DO THAT?
    $date_40_days_before = $row['date_40_days_before'];
    $difference = $date_today - $date_40_days_before ????? // IS IT POSSIBLE TO DO THAT THIS WAY?
    if ($difference <= 40) {
    echo('something ...');
    } else {
    echo('something else ...');
    }

    --------------
    Thanks in advance for all help!
    -tg

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In what format did you store your date in the mysql Database, is it a unix timestamp?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Switzerland
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the format is "date" and it looks like this: e.g. 2003-10.20

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Switzerland
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry: e.g. 2003-10-20

    --> can anyone help me ??

  5. #5
    SitePoint Member
    Join Date
    Oct 2003
    Location
    switzerland
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your $datenow can you do like this.

    PHP Code:
    $datenow date("Y-m-d"); 
    netstreet.ch
    // content management made easy

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Depending on what exactly you're trying to do with your whole script, you could do it in the SQL command via the DATE_SUB() function in mySQL and simply retrieve the difference value. See the manual.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also do things like
    PHP Code:
    $date '2003-10-20';
    echo 
    date('Y-m-d'strtotime($date.' +40 days'));
    echo 
    date('Y-m-d'strtotime($date.' -2 months')); 
    etc..etc..but having the db handle it would be a better choice.

  8. #8
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •