andresapitt Posted December 13, 2010 Share Posted December 13, 2010 I creating a vote system that allows the user to vote once each time. Does anyone have an idea how to check if he already voted today. i save in the database the time-date he voted so i need to chech everytime they are catsing a vote if he already done so today. and it should be that if he voted at 23:59 he will be able to vote again at 00:01 so far i have something very close: $lastVote=strtotime("2010-12-13 11:13:24"); $currentTime=time(); $midnight = mktime(0, 0, 0, date('n'), date('j') + 1); //time to midnight any ideas, cheers- Andrew. Quote Link to comment Share on other sites More sharing options...
Lautarox Posted December 13, 2010 Share Posted December 13, 2010 Well.., you can get the day number by using date(); an comparing the one you saved into the database using date too. Quote Link to comment Share on other sites More sharing options...
andresapitt Posted December 13, 2010 Author Share Posted December 13, 2010 that's a very good point. just doing something like $dateFrom = date("d", $lastVote); $dateTo = date("d", strtotime('now')); if($dateTo==$dateFrom){ $votedToday=true; }else{ $votedToday=false; } would do the trick but, what if they trid to vote in a month time, same day different time, i just thought the was better more professional way to do it instead of doing a bunch of "ifs" Thank you anyway. Quote Link to comment Share on other sites More sharing options...
Lautarox Posted December 13, 2010 Share Posted December 13, 2010 You are right, you can check the month also, the problem is that you want the voters to be able to vote once the day has finished, the only way to do this is to check if its the next day, you can also add the month and the year, it won't be too much, just some ifs Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.