Odds are good that this is done in SQL, not in application code. Here's how to do that in PostgreSQL. (The query seems to work without modification in MySQL 5.6, which surprised me a little bit.)
create table test (
test_id integer primary key,
created_at timestamp not null default current_timestamp
);
insert into test values
(1, current_timestamp),
(2, current_timestamp - interval '1' day),
(3, current_timestamp - interval '10' day);
Use a CASE statement and simple date arithmetic to do pretty much anything you want.
select test_id,
case current_date - cast(created_at as date)
when 0 then 'Added today'
when 1 then 'Added yesterday'
else 'Added some time ago'
end as when_added
from test
order by created_at desc, test_id asc
TEST_ID WHEN_ADDED
--
1 Added today
2 Added yesterday
3 Added some time ago
When you order by created_at desc
, your data is naturally returned in display order (not considering whatever other columns your application might need), and in php you just need to display that "when_added" column. You don't need to do any manipulation in php.