zero-perfoliate
zero-perfoliate

Author Topic: PHP relative time/date format.  (Read 2137 times)

Offline Nick Tompson

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
PHP relative time/date format.
« on: December 22, 2007, 06:09:22 PM »
Hi guys.

Would anyone here be able to help me with a php relative time/date scritp? When i say relative i mean like "X days ago", "X minutes ago", "X seconds ago" and stuff like, "Today, 5:58PM".

I really need it for current project and it is just one of those things that i can't work out.

thanks in advance

erothchild

  • Guest
Re: PHP relative time/date format.
« Reply #1 on: December 24, 2007, 11:26:31 AM »
First you have to get it to tell which day and time to start...
You can use strtotime() or simmilar: then you should end up with a number (a "[Unix] timestamp")... name it X.

Then strtotime("midnight") will give you a number corresponding to 12:00am today (call it A). I

f X>=A then today.
If X<A yesterday: use B=strtotime("yesterday midnight"), and if X>=B then yesterday.

C=strtotime("2 days ago midnight"); if X>=C 2 days ago.

contiue from there...
I'll search my scripts to see if I have one that I can post here for you in a few...

erothchild

  • Guest
Re: PHP relative time/date format.
« Reply #2 on: December 24, 2007, 11:35:29 AM »
I did not find a pre-made script in my batch but I found a strtotime manual for you here: http://us3.php.net/strtotime