0

I have a table , there are 4 fields: name, start date and time (Timestamp) ,end date and time (timpestamp) , car.

In Java/MySQL,

I need to compare database start date time and end start date time and compare with value given in textbox date time field .

Now problem is that we need to book person(driver) and car, if car and person are not booked in given time (that is checked by database) , then we can booked it else not.

Please tell me a logic/query to do this. If you have code please mention it.

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
007
  • 115
  • 1
  • 13
  • What do you mean by compare Start Date and End date in the database and compare the text box value ? .. Are you looking for the duration in the database in time ? – Kenneth Clark Nov 27 '14 at 08:43
  • Are you asking the code? Try yourself and post the code if you have any doubt. See [here](http://stackoverflow.com/a/26839879/3496666) to change date format. – Kumar Nov 27 '14 at 08:57

2 Answers2

1

Try this query,

SELECT name FROM table having '2014-11-28' between start_date and end_date;
0

You can use this query to check availability.
SELECT name FROM table WHERE start_date < '2014-03-13 11:42:28' AND end_date > '2014-03-13 11:42:28' limit 1

If you get any name, then you can not book new driver. Also look at mysql date and time functions.

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82