I'm am trying to take a UNIX timestamp and convert it into a string with PHP. This is easy given PHP's built in functions however I have a specific set of requirements which are causing me some confusion.
The logic should be as follows:
- if timestamp is today - return
today - if timstamp happened yesterday - return
yesterday - if timestamp is older than yesterday but still this week return the
day name( Thursday, Tuesday etc.) - if timestamp happened last week - return
last week - if timestamp is older than last week - return
Month and Year( formatted as June 2013, January 2011 etc.)
This appears quite simply from the outset but for some reason my brain is confusing itself over the matter.
Please Note: I do not want a solution based on pure arithmetic as the modern calendar system is quite complex and for accuracy I would like to use built in time functions which account for this. strtotime(), date() etc.
Thanks in advance
EDIT: The initial part of the logic that I am using so far is as follows. Of course this will only return today if the time stamp is today. I need to extend this to account for the other requirements. Perhaps using strtotime?
public function getTimeChange($timestamp)
{
$today = date('Ymd');
$date = date(Ymd', $timestamp);
if($date == $today){
return 'today';
}
}
ifstatements to handle the special cases you mentioned. start there.