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
https://forums.phpfreaks.com/topic/200437-time-interval/
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
https://forums.phpfreaks.com/topic/200437-time-interval/#findComment-1052072
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
https://forums.phpfreaks.com/topic/200437-time-interval/#findComment-1052599
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
https://forums.phpfreaks.com/topic/200437-time-interval/#findComment-1053289
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
https://forums.phpfreaks.com/topic/200437-time-interval/#findComment-1053411
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.