0

I am developing a book/library app. I want to give users the option of 'reserving' a book until the following working day (5pm). After this the book should become available again, that is another question for another day!

Currently once the user clicks 'Reserve' I insert a number of records into my 'borrow_request' table. These are as follows;

borrow_id
book_id
user_id
date_request
date_expire

My date_request variable is;

$date_request = date("Y-m-d H:i:s");

How can I insert a date_expire variable and increment it by one working day?

The next step I will investigate is how to reset the date_expire after one working day, possibly a cron job?

Quite new to php/mysql here so any advice is appreciated.

jonboy
  • 2,729
  • 6
  • 37
  • 77

1 Answers1

1

Instead of a cron job you should use mysql events which allow you to run queries after a certain amount of time. To add a day to the date you could:

<?php
$stop_date = '2009-09-30 20:24:00';
echo 'date before day adding: ' . $stop_date; 
$stop_date = date('Y-m-d H:i:s', strtotime($stop_date . ' + 1 day'));
echo 'date after adding 1 day: ' . $stop_date;
?>

taken from: https://stackoverflow.com/a/1394811/

for the question: adding one day to a date

You should have googled it first there are many answers here in stack overflow already like the one I'm posting

Community
  • 1
  • 1
zardilior
  • 2,810
  • 25
  • 30
  • what is the proper place to write 'I agree with the change' in this site Fred? As comments shouldn't be used to thank and stuff like that – zardilior Dec 22 '14 at 15:49