Description:
select Paid_Status,Last_Payment,Valid_Days,DATEDIFF(NOW(),Last_Payment) AS UsedDays, Valid_Days - DATEDIFF(NOW(),Last_Payment) AS RemaingDays FROM studentdetails limit 10;
+-------------+---------------------+------------+----------+----------------------+
| Paid_Status | Last_Payment | Valid_Days | UsedDays | RemaingDays |
+-------------+---------------------+------------+----------+----------------------+
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 1 | 2008-10-09 12:59:50 | 30 | 33 | 18446744073709551613 |
| 1 | 2008-10-09 13:05:10 | 10 | 33 | 18446744073709551593 |
| 1 | 2008-10-09 13:05:17 | 30 | 33 | 18446744073709551613 |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
+-------------+---------------------+------------+----------+----------------------+
look in to the above query and the result the RemaingDays column have return wrong result when Valid_Days coulmn have less value compare with UsedDays column ,at that time it will return wrong values. it only come in select query using with columns. if we give direct value it will return actual result. Kindly resolve the problem immediatly.
How to repeat:
select Paid_Status,Last_Payment,Valid_Days,DATEDIFF(NOW(),Last_Payment) AS UsedDays, Valid_Days - DATEDIFF(NOW(),Last_Payment) AS RemaingDays FROM studentdetails limit 10;
+-------------+---------------------+------------+----------+----------------------+
| Paid_Status | Last_Payment | Valid_Days | UsedDays | RemaingDays |
+-------------+---------------------+------------+----------+----------------------+
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 1 | 2008-10-09 12:59:50 | 30 | 33 | 18446744073709551613 |
| 1 | 2008-10-09 13:05:10 | 10 | 33 | 18446744073709551593 |
| 1 | 2008-10-09 13:05:17 | 30 | 33 | 18446744073709551613 |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
| 0 | 0000-00-00 00:00:00 | 0 | NULL | NULL |
+-------------+---------------------+------------+----------+----------------------+
Suggested fix:
check the both values at the time of minus(subraction).