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?
Thanks
If you’re using timestamps to store dates in the database:
You can have preset intervals like:
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:
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.