Time and Date
Moderator: General Moderators
Time and Date
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
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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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"
Make sure you set the criteria to author "printf" and forum is set to "Code Snipplets"
Re: Time and Date
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.
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.
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
time() - mktime(...);