Jump to content

Can't get my head aroud date time MYSQL - hopefully simple question.


Anidazen

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.