If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Time stamp and time reference

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-09, 08:55
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
Time stamp and time reference

Hello

I wanted to create in my web page a script that calculates how many hours/days/months ago something was uploaded to the database.

e.g.

I uploaded an ad to my site today at 08:00
now lets say its 10:00, so i want to have a text saying
"added 2 hrs ago"
lets say 3 days passed
"added 3 days ago"
and so on....

I tried something but couldnt get it to work.

any suggestions ?

Danny
Reply With Quote
  #2 (permalink)  
Old 07-15-09, 09:28
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,260
so what did you try
have a look at the MySQL date/time functions in da manuel
MySQL :: MySQL 5.1 Reference Manual :: 11.6 Date and Time Functions
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 07-15-09, 09:56
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
Hello there,

well thats the problem i didnt realy understand that...

what i did was....MANUALLY added a "date" column

then with php, set a variable for today

then subtracting ... stuppid i know!

well any help would be appriciated

Danny
Reply With Quote
  #4 (permalink)  
Old 07-15-09, 13:35
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,260
select timediff(now(),mydatecolumn) as ElapsedTime from MyTable

then use column ElapsedTime

..of course you could do the same calculation in your front end, forget the sordid details in PHP
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On