6 Replies - 331 Views - Last Post: 04 November 2013 - 02:15 PM Rate Topic: -----

#1 iLiTH  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 123
  • Joined: 25-August 13

"Time Ago" using DateTime() Class?

Posted 03 November 2013 - 04:55 PM

I was reading about this nifty class that PHP possesses. I was wondering if anyone here could help me figure out how to do the whole "Posted {some time} ago." using this class-a-ma-bob. >.<
Is This A Good Question/Topic? 0
  • +

Replies To: "Time Ago" using DateTime() Class?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3358
  • View blog
  • Posts: 11,372
  • Joined: 12-December 12

Re: "Time Ago" using DateTime() Class?

Posted 03 November 2013 - 05:10 PM

What have you tried?

The first step would be to achieve a simple echo that prints a formatted version of the current date.
Was This Post Helpful? 0
  • +
  • -

#3 iLiTH  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 123
  • Joined: 25-August 13

Re: "Time Ago" using DateTime() Class?

Posted 03 November 2013 - 05:11 PM

View Postandrewsw, on 03 November 2013 - 05:10 PM, said:

What have you tried?

The first step would be to achieve a simple echo that prints a formatted version of the current date.


Oh, that's easy. I tried using $date->diff($now) and echoing that, where $now is defined by time(). After that, though... :L
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3358
  • View blog
  • Posts: 11,372
  • Joined: 12-December 12

Re: "Time Ago" using DateTime() Class?

Posted 03 November 2013 - 05:33 PM

Quote

After that, though... :L

No idea. Go wild? Fill your boots! Get your date on!
Was This Post Helpful? 0
  • +
  • -

#5 Hqtitan  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 51
  • Joined: 28-August 10

Re: "Time Ago" using DateTime() Class?

Posted 04 November 2013 - 09:59 AM

Have you tried storing the date with the post, and then finding the difference between that and the current date? Once you know that, you can format and display it. It's been quite a bit of time since I've done this, but I remember that it was fairly easy to find with a bit of Googling.

This post has been edited by Hqtitan: 04 November 2013 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#6 iLiTH  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 123
  • Joined: 25-August 13

Re: "Time Ago" using DateTime() Class?

Posted 04 November 2013 - 10:03 AM

I've tried, but it failed to work as planned. Some huge-o error about something I can't remember. I also need to figure out how long ago in any unit of time it was; seconds, minutes, hours, weeks, etc...
Was This Post Helpful? 0
  • +
  • -

#7 Hqtitan  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 51
  • Joined: 28-August 10

Re: "Time Ago" using DateTime() Class?

Posted 04 November 2013 - 02:15 PM

If I remember correctly, the date function returns time in seconds measured from January 1, 1970. You should be able to convert from there. If you look around, there might even be a function out there to do such conversions.


This might help you:
http://php.net/manua...ion.getdate.php

This post has been edited by Hqtitan: 04 November 2013 - 02:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1