I have a database of expiry dates. In this database I have 4 columns specifically for dates. I want to be able to compare all the 4 dates (in the 4 columns) for each of the rows and echo the database ordered by those expiring soon on top followed in that order. To be more clear : the 4 dates in each row should be compared to the ones in other rows and there is no need for any logic here. even if one date in one of the row is earlier then any other date in the other row then that row with the former date should be echoed first. My question is can I use PhP conditional statements to compare dates. If not how else can i approach this problem ?
Asked
Active
Viewed 61 times
2 Answers
0
Use time stamps!
You could fetch them in sql by
UNIX_TIMESTAMP(yourdate)
In your select statement

Tob
- 627
- 6
- 9
0
If you want to use only PHP, it becomes very expensive for the DB doing what you want.
Maybe you should use the mysql ORDER BY
statement like here
-
But order by can only compare rows in a particular column right? what if I want to order them based on all 4 columns in each row? – Gowthaman Prabhu May 26 '16 at 07:08
-
In the link there is the answer: `SELECT * FROM table_name WHERE your_condition ORDER BY date1 DESC, date2 DESC, date3 DESC, date4 DESC` – bennes May 26 '16 at 08:12