Fetch difference between two timestamps in seconds

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Darla
Forum Newbie
Posts: 16
Joined: Mon Feb 12, 2007 8:27 am

Fetch difference between two timestamps in seconds

Post by Darla »

Hello

I have a database table where each record has a timestamp (created using the NOW() function perhaps CURRENT_TIMESTAMP is more correct to use?)

I wish to make a simple query which compare timestamp of right now with the timestamp in the database and returns the difference in seconds.

Is there some easy way to do this?

Darla
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

select (UNIX_TIMESTAMP(NOW())-myTimestamp) as difference from myTable
Maybe. I've not tried it.
Darla
Forum Newbie
Posts: 16
Joined: Mon Feb 12, 2007 8:27 am

Post by Darla »

Thanks, I'll try it out but am having some problems with my server now :(
Post Reply