September 30th, 2012, 12:14 PM
Mysql date format
i have a comment script on my website and when a user posts a comment the date shows example Posted :30 september 2012, my date format is %d %b %y...how can i change this to show
Posted : 6 Days ago....
September 30th, 2012, 01:17 PM
i've done something similar before. You dump the date value into php and let your script calculate the difference. i don't guarantee the syntax is perfect since it's just off the top of my head from memory, but something along the lines of this should work :
*** somewhere up here you will have your mySQL recordset. "thePostDate" is assumed to be a standard date/time format***
$value1 = htmlentities($row_DatabaseRecord['thePostDate']; //gets the date from the database record
$today = time(); // standard function to get today's date
$days_since = ceil(abs($today - $value1) / 86400); // calculates the amount of days since the post, and rounds it to the nearest day
$outputString = "It has been ".$days_since." days since the post."; // creates the report string
i highly doubt that's perfect code but all the elements are there. a couple of tweaks and it should work for you.