Jump to content

time interval


buladex

Recommended Posts

i need time restriction of 12 hours for voting system, my code looks like this but doesnt respect 12h interval, some time after time pass 00:00 ppl can vote endless until next day at 12:00:

$sql="SELECT * FROM $tbl_name WHERE DATE_ADD(CURRENT_DATE(), INTERVAL 12 HOUR) > `last_voted`  and name='$myusername'";

 

any suggestion????

i also try CURRENT_TIME() and didn not work

Link to comment
Share on other sites

Doesn't make sense because for one, CURRENT_DATE() should be already be greater than last_voted, so adding 12 hours to it doesn't do anything. I think you want to subtract or add 12 hours to last_voted. But your logic is off.

Link to comment
Share on other sites

im using sql , and my last_voted is a like this `last_voted` = NOW() table save,  i tried them all above, atm i have it set like this: $sql="SELECT * FROM $tbl_name WHERE DATE_ADD(CURRENT_DATE(), INTERVAL -12 HOUR) > `last_voted`  and name='$myusername'";  works at this time but i need to see later if works cuz i cant change my computer time.

ty all for helping ill let u know later if its working

Link to comment
Share on other sites

Hi Buladex

 

I one of decisions you may try to convert time to timestamp and then compare time (by using UNIX_TIMESTAMP() function). Or you may try better solution - TIMESTAMPDIFF() function. Something like this:

TIMESTAMPDIFF(HOUR, `your_time`, NOW()) < 12 or ... > 12 depending on what do you want check. Let me know it this is help you if not - post SQL script you used and examples from DB.

 

Thanks.

Link to comment
Share on other sites

atm i droped on using time and i do it manualy at 12 h but i need it to make automatic so how does it work to add 12 h in sql and decrease automatic to 0, using time stamp? i mean if u vot u add in sql table +43200 seconnds(12h) what attribute should have the sql table time?timestamp?

Link to comment
Share on other sites

Hi buladex,

That's very strange :)

As I understand your condition is not working only if pass 12 hours sharp. Did you try to use `<=` `>=` instead `<` `>`?

About your question: You may convert time to timestamp by UNIX_TIMESTAMP() as I said before or set timestamp as type of your field.

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.