1

I'm fairly new to MYSQL and PHP, and i'm working on a project for a security department. The guards work in 2 teams of 12 hour. (7am - 7pm and 7pm - 7am). They log events that happened during their shift to a database, and now i would like to be able to select only the data from each shift.

I use this for the 7AM - 7PM: $sql = "SELECT * FROM table WHERE date >'".date("Y-m-d 07:00:00")."' AND date <'".date("Y-m-d 19:00:00")."'";

but I don't seem to be able to find out how I can do the same for the 7pm (previous day) to 7 am.

Most answers I find tell me how to select previous day, but none tells for a specific time during that day.

  • find yesterday's date: http://stackoverflow.com/questions/6796866/php-date-yesterday the date() routine just formats dates, but it can accept a second parameter for the date (in unix time) so if you subtract the number of seconds in a 24 hour day you can get yesterday's date. date("Y-m-d 19:00:00", time() - 24 * 60 * 60) – fbas May 10 '15 at 21:43
  • What's wrong with the query you have, but with the dates and times set for 7pm start and 7am stop? –  May 10 '15 at 21:47
  • possible duplicate of [MySQL Get Yesterday Content](http://stackoverflow.com/questions/16065334/mysql-get-yesterday-content) –  May 10 '15 at 21:48

0 Answers0