I have a database table. It has several hundred entries and each entry is timestamped. I’m looking to only output each day and not have it duplicate any days.
Data:
2009-02-04 06:20:27
2009-02-04 06:20:27
2009-02-05 06:20:27
2009-02-07 06:20:27
2009-02-07 06:20:27
2009-02-07 06:20:27
Output should only be (time is irrelevant):
2009-02-04 06:20:27
2009-02-05 06:20:27
2009-02-07 06:20:27
What is the best way to accomplish this? Should I really be cycling through each row and comparing one from another? Just doesn’t seem efficient. Any ideas/tips?
You would want to do this on the database level using the mysql DISTINCT keyword:
This will make it so if there are duplicate dates, only one is returned. Read more about it here.