Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datetime / timestamp question

Status
Not open for further replies.

brownheezo

Programmer
Jun 20, 2003
1
US
Is there any way of saying "tem minutes ago"?

Example:
select userID from users where joined = NOW() - 1000

I'm trying to say give me all of the users that joined exactly 10 minutes ago. This would work for most cases if you were using timestamp, but if it's January 1, 2004 12:00AM, it won't get the proper results.

I could do it in PHP, but I'm trying to stay away from it.

Any tips, or hidden functions that I should know about?

Thanks in advance
 
Are you using MySQL's datetime function?
Unfortunately, for what you want, mysql is VERY limited, which is why many will use backend scripting to determine that value, especially with adding and subtracting time.

personally, I never use mysql's date/datetime/timestamp functions because of the many date / time calculations i do within my pages or projects.


explains it better. About the only thing MySQL's date/datetime/timestamps are good for is for subtracting or adding days. Not specific "time" amts.

Work with unix timestamps. Much easier to calculate.
 
Something like
[tt]select userID from users where UNIX_TIMESTAMP(joined) = NOW() - 600[/tt]
should work if your column is of a MySQL time family type.

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top