Anidazen Posted March 29, 2007 Share Posted March 29, 2007 Hello, Cheers for reading. Basically, I simply want to record a time with every SQL insert, and then use a function to count how many times that same user (identified by IP) has run the script in the last 24 hours. So all I want is a format to record in SQL and then a query to check this. With PHP unix timestamp this would be a simple matter of returning where the timestamp is greater than time() - 86400 (the number of seconds in 24 hours). However, I don't know how to set UNIX timestamps... Anyone able to help? Link to comment https://forums.phpfreaks.com/topic/44774-cant-get-my-head-aroud-date-time-mysql-hopefully-simple-question/ Share on other sites More sharing options...
monk.e.boy Posted March 29, 2007 Share Posted March 29, 2007 In SQL you can use the built in function NOW(), so you INSERT would look like: INSERT INTO table (ip,user_id,time) VALUES('10.01.10.01',99,NOW()) This will use the current time as the value. You can also use the DATE TIME functions (google mysql date functions ) to do some maths like: NOW()-24hours Put this in you select SELECT name FROM table JOIN users ON users.id=table.user_id WHERE time > (NOW()-24hours) monk.e.boy Link to comment https://forums.phpfreaks.com/topic/44774-cant-get-my-head-aroud-date-time-mysql-hopefully-simple-question/#findComment-217385 Share on other sites More sharing options...
monk.e.boy Posted March 29, 2007 Share Posted March 29, 2007 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html monk.e.boy Link to comment https://forums.phpfreaks.com/topic/44774-cant-get-my-head-aroud-date-time-mysql-hopefully-simple-question/#findComment-217388 Share on other sites More sharing options...
Anidazen Posted March 29, 2007 Author Share Posted March 29, 2007 Thanks monk.e.boy - that's very helpful. Good man. Link to comment https://forums.phpfreaks.com/topic/44774-cant-get-my-head-aroud-date-time-mysql-hopefully-simple-question/#findComment-217488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.