PHP Date Question
date, php
Solution
Try this:
$shoutDate = date('Y-m-d', $shoutTime);
if ($shoutDate == date('Y-m-d'))
return date('H:i', $shoutTime);
if ($shoutDate == date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))))
return 'yesterday';
return gregoriantojd(date('m'), date('d'), date('y')) - gregoriantojd(date('m', $shoutTime), date('d', $shoutTime), date('y', $shoutTime)) . ' days ago';
Problem
I am trying to do a little bit of math using dates in PHP. I am modifying a shoutbox, and I want to implement the following functionality. If post date = today, return time of post else if date = yesterday, return "yesterday" else date = X days ago How would I use php's date functions to calculate how many days ago a timestamp is (the timestamp is formatted in UNIX time)