Page 1 of 2
Time and Date
Posted: Sun Oct 15, 2006 8:15 am
by tommy1987
I have the following fields stored in a mySQL database:
Date, in the format: 2006-10-15
Time, in the format: 01:30:54
I want to be able to take this information and display how long ago it was since today. e.g. 4 seconds ago, or 2 minutes ago, or 1 day ago, or 1 month ago.
What is the best way of doing this, will I need to write my own algorithm to calculate it?
Thanks Tom
Posted: Sun Oct 15, 2006 8:20 am
by feyd
look for printf's function in Code Snippets.
Posted: Sun Oct 15, 2006 8:27 am
by tommy1987
excuse my ignorance but where is the code snippets?
Posted: Sun Oct 15, 2006 8:47 am
by feyd
Posted: Sun Oct 15, 2006 9:09 am
by Oren
Double posting haa
feyd... One of the mods/admins should ban you for that

Posted: Sun Oct 15, 2006 10:55 am
by feyd
Oren wrote:Double posting haa
feyd... One of the mods/admins should ban you for that

huh, weird.. when I thought I may have double posted that and checked, it wasn't there. Oh well, deleted.
Posted: Sun Oct 15, 2006 5:10 pm
by tommy1987
I cant seem to find the piece of code specified in the code snippets forum, any other ideas?
Posted: Sun Oct 15, 2006 5:15 pm
by volka
search.php
Search for Author:
printf
Forum:
Code Snippets
returns two results
Posted: Sun Oct 15, 2006 5:15 pm
by John Cartwright
A very valuable tool on our forums is the
search feature.
Make sure you set the criteria to author "printf" and forum is set to "Code Snipplets"
Posted: Sun Oct 15, 2006 5:17 pm
by tommy1987
i beg your pardon, I thought you were referring to a function called printf.
Sorry

Posted: Sun Oct 15, 2006 5:26 pm
by volka
no excuse

even a search for the keyword:printf only returns four results for the forum: Code Snippets
* (Swift) PHP Mailer class with plugin support
* Automatic php2js convertion
* time -> seconds to array(y,w,d,h,m,s)
* Array Debugging

Re: Time and Date
Posted: Sun Oct 15, 2006 10:42 pm
by sujon
tommy1987 wrote:I have the following fields stored in a mySQL database:
Date, in the format: 2006-10-15
Time, in the format: 01:30:54
I want to be able to take this information and display how long ago it was since today. e.g. 4 seconds ago, or 2 minutes ago, or 1 day ago, or 1 month ago.
What is the best way of doing this, will I need to write my own algorithm to calculate it?
Thanks Tom
Sujon wrote: Actually u can write ur own algorithm by using this concept
$currentDate = date("Y-m-d");
$yesterday= date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")-1, date("Y")));
$tomorrow= date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));
I hope u'll solve ur pproblem.
Thanks.
Posted: Mon Oct 16, 2006 10:52 am
by tommy1987
this is exactly what I want but...
I need to get the time elapsed since the original time to whatever the date and time it is currently in seconds to then pass to this function.
Does anybody know of a way to do this, since obviously different months have different amounts of days etc..
To clarify the problem, imagine a forum and someone posts, then when redrawing the page in future the script will calculate how long ago this was in seconds then pass this to
printf's function.
Hope there is something which someone knows of which makes my job a bit easier.
Thanks in advance for any help.
Posted: Mon Oct 16, 2006 11:01 am
by feyd
Posted: Mon Oct 16, 2006 11:07 am
by tommy1987
thanks very much for that. Looks to be just what I am after..