All good mood! I'm learning, do not kick) Help make a query mysql

There is a table in which the start_date and start_time columns

I do a sample

SELECT * FROM history WHERE start_date BETWEEN '$start_date' AND '$stop_date' 

How to change the query so that time also participates in sorting?

  • one
    You need to store the date-time in a single datetime column - Mike
  • then everything else will have to be rewritten) - Dimastik86
  • Yes, but sometimes it is still convenient to store in UNIX seconds INT(11) which can be simply obtained using the time() function and then converted to date() when displayed. - fonjeekay
  • What type of data does the start_date column start_date ? - fonjeekay
  • year-month-day 2017-01-20 - Dimastik86

1 answer 1

SELECT * FROM history WHERE start_date BETWEEN '$start_date' AND '$stop_date' AND start_time BETWEEN '$start_time' AND '$stop_time';

But it is better to follow the recommendations and move the date and time in one column.

The rest that follows this code will not have to be rewritten. You can select select 2 times one datetime field and bring it separately to date and separately to time by giving them the appropriate aliases.