Anyone can help me how to calculate between two days in php?

Discussion in 'PHP' started by zhelpretty02, Jan 22, 2009.

  1. #1
    Once the book/s is selected from the dropdown listbox the program will automatically set the book’s return date deadline 1 week after the date borrowed. If a book is returned later than that date there will be a penalty of P10 a day.


    Thanks!;)
     
    zhelpretty02, Jan 22, 2009 IP
  2. mrmaf

    mrmaf Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi zhelpretty02, This is the code that gives you number of days between two dates
    $days = (strtotime(date("Y-m-d"))-strtotime("2009-1-20") ) / (60 * 60 * 24);

    echo $days;

    Now utilize this code according to your program logic.
     
    mrmaf, Jan 23, 2009 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    If you store a GMT UNIX timestamp keeping track of then the book was checked out.

    if(time() - $checkout_timestamp > 604800)
    {
       //book is late
    }
    Code (markup):
     
    joebert, Jan 23, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Timestamps are in seconds. That's where you gonna start.

    The two codes above should gives you the idea.
     
    ads2help, Jan 23, 2009 IP
  5. zhelpretty02

    zhelpretty02 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you so much for the help. It helps me a lot.. :)
     
    zhelpretty02, Jan 27, 2009 IP