0

I'm trying to count the number of days left, NOTE: Due date is available in database, but number of days left not stored in the database

$sql="SELECT count(id) AS total FROM clients WHERE round((((strtotime.due_date- 
   time())/24)/60)/60))<=30";
   $result=mysqli_query($con,$sql);
   $values=mysqli_fetch_assoc($result);
   $num_rows=$values['total'];
   echo $num_rows ;
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • time() for current time – Erick Boniventure Jul 17 '22 at 09:29
  • `WHERE DATEDIFF(due_date, NOW()) <= 30` if due_date is in the future – Honk der Hase Jul 17 '22 at 09:31
  • The proper way to do it in MySQL is using DATE DIFF ([How to get the number of days of difference between two dates on MySQL?](https://stackoverflow.com/questions/2490173/how-to-get-the-number-of-days-of-difference-between-two-dates-on-mysql)). Your manual calculation assumes that all days have 24 hours, which isn't true in many countries. – Álvaro González Jul 17 '22 at 09:58
  • Question was closed before I could vote it as duplicate of https://stackoverflow.com/questions/2040560/finding-the-number-of-days-between-two-dates - Just please don't use the accepted answer, use `DateTime->diff()` instead. – Álvaro González Jul 17 '22 at 09:59

0 Answers0