Jump to content

check if same we are in the same day (time till midnight)


andresapitt

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.