Time and strings

Discussion in 'PHP' started by timallard, Jan 26, 2011.

  1. #1
    I am trying to see if one date is within a 24 hour period. If so, do not allow something, if it is outside of that 24 hour period, do something.

    $now = date("Y-m-d : H:i:s", time());
    $twenty4hoursPrevious = date('Y-m-d : H:i:s', strtotime('-1 day'));

    i believe this is right so far but when i get to comparing i get the wrong result.

    if($twenty4hoursPrevious < $now) {
    //do nothing
    } else {
    //do something
    }

    any ideas?

    Thanks!
     
    Last edited: Jan 26, 2011
    timallard, Jan 26, 2011 IP
  2. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #2
    Figured it out. I wasnt converting another value to string. I also reworked the problem.

    $fbuserLastVoteTime = "2011-01-10 12:12:12"; //$row['timestamp'];

    $now = strtotime(date("Y-m-d H:i:s"));
    $nowMinus24hours = strtotime('-24 hours', $now);


    echo "Last Vote Time: " . strtotime($fbuserLastVoteTime) . "<br>";
    echo "Now: " . strtotime($now) . "<br>";
    echo "24 hours previous: " . $nowMinus24hours . "<br>";

    if($fbuserLastVoteTime < $nowMinus24hours) {
    echo "good to go";
    } else {
    echo "cant vote";
    }



    woop
     
    timallard, Jan 26, 2011 IP
  3. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #3
    I am little dissoriented, so this script checks if user voted in last 24 hours and if yes, your system won't allow them to vote again, however if they didn't voted in last 24 hours they can vote. Am I right? I know you don't need support anymore, but looks like good script so I'm interested :)
     
    G3n3s!s, Jan 26, 2011 IP