Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Adding a (added $ days ago) script, need help

    Hi

    I am trying to write some php that outputs how long ago something was added to my database.

    Just wondered what the easiest way of doing it is?

    so it will output something like:
    (added 2 days ago) or (added today) etc

    Hope you can help

  • #2
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Run the query such as:

    PHP Code:
    "SELECT date FROM content WHERE id=$id" 
    And then fetch it to an array and wherever you want that date to be shown, add the echo for the row. You can change the date format to what you wish either in php, or I think during the query of the database
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I will expand a little on this one as well.
    Depending on the format you save it, you will want to take the posted time in the database, and subtract it from the current time. The resulting time can be formatted to determine how many days ago it was posted with some rather simplistic calculations.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    adze (01-17-2008)

  • #4
    New Coder
    Join Date
    Oct 2007
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    cheers guys, makes sense now!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •