title: Compare date and time to current time in MySQL
body: <p>I am working on a Office Management System in php and I want to create two appointment datatables. One will show previous appointments in descending order and other will show upcoming appointments in ascending order of date and time. Now in my MySQL Database I have date and time as different parameters. Now should I fetch all entries from database and filter using php and show them in different datatables or should I fetch entries using a filtered query and then show them in different datatables.
  I have tried these filtered queries but these are not working:</p>
  <p><strong>For Upcoming</strong></p>
  <p><code>$sql = &quot;SELECT * FROM p_appointment WHERE UNIX_TIMESTAMP(STR_TO_DATE(CONCAT(date,' ',time), '%Y-%m-%d %H:%i:%s')) &gt;= UNIX_TIMESTAMP(now()) ORDER BY date ASC</code></p>
  <p><strong>For Previous</strong></p>
  <p><code>$sql = &quot;SELECT * FROM p_appointment WHERE UNIX_TIMESTAMP(STR_TO_DATE(CONCAT(date,' ',time), '%Y-%m-%d %H:%i:%s')) &lt; UNIX_TIMESTAMP(now()) ORDER BY date DESC</code></p>
  <p>date is being stored in format 28/07/2021 and time as 2:25 PM
  Any solution using php or MySQL will be helpful.</p>