Time/Date - posted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesti
    New Member
    • Nov 2007
    • 144

    Time/Date - posted

    hi,

    i'm new to php.
    how to show the time / date, a message is posted. like in forums, there are something like, "5 minutes ago", "8 hourse 17 minutes ago", "Yesterdar" , "10-07-2008". in every post.

    thanks
  • Jeigh
    New Member
    • Jul 2007
    • 73

    #2
    You'll have to store the time in the database. Make this column datetime eg:

    Code:
    ALTER TABLE somthing ADD date_added datetime NOT NULL DEFAULT "0000-00-00 00:00:00"
    You can get the current time by usind the date(); function in PHP:

    [PHP]
    $date = date('Y-m-d H:i:s', time());
    [/PHP]

    This will give you time in the format yyyy-mm-dd hh-mm-ss. As for displaying it in formats such as 'Yesterday' and '5 Days Ago' etc. you will need to do additional PHP coding.

    Comment

    Working...