Little help with this & quot; date & quot; function


I have this to select a date from a mysql db, and compare it to an array of month-names in swedish language.

$monthnames = array("","Januari","Februari","Mars","April","Maj","Juni","Juli","Augusti","September","Oktober","November","December");

$postdate = $monthnames[date("n", strtotime( $row['modify_date'] ))];
//Outputs something like '12 Februari'

Here is the prob, I want to check the $postdate variable and change it to "Today", "Yesterday" and "Day before yesterday" according to the date, how can I do so?


If you're using timestamps to store dates in the database:

You can have preset intervals like:

$day = mktime(0,0,0,2,1,2001)-mktime(0,0,0,1,1,2001);

And you can compare the time now - timestamps/dates you have in the database with those intervals.

For example, let's say $dbTime contains a timestamp fetched with mysql:

$time = time() - $dbTime;
   echo 'posted today';
   echo 'posted yesterday';

etc etc.

Then you can use PHP's Date function to echo hrs, minutes, secs, or dates, if they are larger than your predefined intervals.