views:

41

answers:

3

I am pulling a row from a mysql database which has a time stamp, like this: 2010-10-10 16:56:23

I need to compare this time stamp to the current time from the date object, and see if 30 minutes has passed.

thanks!

A: 

2010-10-10 16:56:23

make it 20101010165623

get current time also in this format

Just compare bot as integer itself.

You got it!.

Or

mysql have datediff() function which will help you.

http://www.w3schools.com/SQl/func_datediff_mysql.asp

in the example , your case second paramtere will be now()

zod
Wrong. This cannot be used to check whether 30 minutes have passed.
SLaks
+1  A: 

How about:

(new Date() - Date.parse('2010-10-10 16:56:23')) >= 1000 * 60 * 30 // (current date - date) >= 30 minutes

I'm not sure about the whole time zone thing though.. if the timezones between the server and user are different you may need to mess around with that.

CD Sanchez
A: 

Use DATE_ADD function and cast date type to your string

NOW() > DATE_ADD(CAST('2010-10-10 16:56:23' AS date), INTERVAL 30 MINUTE)

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast

lashtal