TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Difference between timestamps (http://www.talkphp.com/general/5529-difference-between-timestamps.html)

Killswitch 07-16-2010 05:32 PM

Difference between timestamps
 
I know, this should be an incredibly easy task but for some reason I just cannot get it to work properly.

I have a comment form that needs to check a users last post time to the current, and see if at least 30 seconds have passed before allowing them to post again.

The users last post is stored as datetime (Y d m H i s), and the current time is generated as time().

I am converting the users datetime with strtotime, and checked that it worked by using a timestamp converter.

How would I gather a 30 second time difference between the two? I've been trying to add 30 to the users time, which is obviously wrong because when I print that back out, I get a timestamp for something like January of 2051 :(

If anyone can help, I would much appreciate it!

Village Idiot 07-16-2010 07:46 PM

Quote:

Originally Posted by Killswitch (Post 30845)
I know, this should be an incredibly easy task but for some reason I just cannot get it to work properly.

I have a comment form that needs to check a users last post time to the current, and see if at least 30 seconds have passed before allowing them to post again.

The users last post is stored as datetime (Y d m H i s), and the current time is generated as time().

I am converting the users datetime with strtotime, and checked that it worked by using a timestamp converter.

How would I gather a 30 second time difference between the two? I've been trying to add 30 to the users time, which is obviously wrong because when I print that back out, I get a timestamp for something like January of 2051 :(

If anyone can help, I would much appreciate it!

First off, always store your times as timestamps. It is considerably easier to work with the numbers and convert to a string when you need it than vice versa.

You would get a thirty second time difference when laterStamp-firstStamp>=30.


All times are GMT. The time now is 09:54 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0