#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Mysql date format


    Hi all...

    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....

    Kind regards

    Ronan
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    6
    Rep Power
    0
    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***
    <?php

    $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

    echo $outputString;

    ?>


    i highly doubt that's perfect code but all the elements are there. a couple of tweaks and it should work for you.

IMN logo majestic logo threadwatch logo seochat tools logo