Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:17:05+00:00 2026-06-14T13:17:05+00:00

I got a voting script that allow people to vote for an item in

  • 0

I got a voting script that allow people to vote for an item in the database every 24 hour and some more code to check if 24 hours have past or not using 'NOW()' and 'DATE_SUB( NOW(), 'INTERVAL 1 DAY'.

I’m currently trying to add the feature to display how much time is left before the user can vote again using the code below.

$time = explode(" ", $voteCheck[1]);
$year = explode("-", $time[0]);
$date = explode(":", $time[1]);

// Set it all to one long string
$time = $year[0].$year[1].$year[2].$date[0].$date[1].$date[2];

// Current time and date
$cTime = date("YmdHis");

// I get lost here

votcheck is an array from a sql string which just returns the first row as 0 or 1.
1 if the user already voted and 0 if the user can vote again.
The second row returns the date and time the user voted.
I just can’t seem to figure out what to do to get the x amount of hours left before the user can vote again.

My main problem is that the length of the $time string sometime is 13 and sometime 14 characters long.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:17:06+00:00Added an answer on June 14, 2026 at 1:17 pm

    Ok here it is

    $voted = new DateTime($time);
    $daylater = date('Y-m-d H:i:s', strtotime('+1 day', $voted->format('U')));
    $canvote = new DateTime($daylater);
    $now = new DateTime(date("Y-m-d H:i:s"));
    
    $diff = $canvote->format('U') - $now->format('U'); 
    
    if ( $diff > 0 && $diff < 86400 ) {
        $left = gmdate("H:i:s", $diff);
        echo $left . ' left till you can vote again';
    } else {
        echo 'You can vote again' ;
    }
    

    Let me know if it works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got some problems. Built an applet that has to be used step-by-step. After each
Got a problem with my add function to my database. The following code hangs
I've got a Rails app that'll be sitting on top of a legacy database
(NOTE: Source code here https://github.com/cthielen/dss-evote ) I've got a simple voting application. A survey
Got a bug in some legacy code which communicates with a payment terminal. Just
Got a programm with 2 threads. one thread is writing some stuff into the
Got this error message while trying to load view: The model item passed into
Got a question for some jQuery wizard who might stumble upon this. When I
Got a seg fault from my memcpy that gdb can't give me anything else
Im working on a website that is bassed around voting for posts. the website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.