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 8817001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:44:50+00:00 2026-06-14T04:44:50+00:00

I have a drop down menu which displays an exam’s name, date and time

  • 0

I have a drop down menu which displays an exam’s name, date and time and what I want to do is that if an exam date has been passed from the current date or time, then the text is displayed in red, else text is green.

Problem I am having is that if the current date is 10-11-2012 (which is today) and if an exam has this date and time below:

10-11-2012, 16:00:00

It displays the text in red and not in green. The problem is that it is not recognising the current time, it thinks that as it is the current date, it should be red, but because the current time hasn’t passed in the current date, then it should be green.

The database stores the date as 2012-11-10 and the time in the database stored as 16:00:00. While in the drop down as mentioned it is stored as: 10-11-2012, 16:00:00

Below is the code:

<style>
.red{ color:red; }
.green{ color:green; }
</style>

…

    $now = date("Y-m-d h:i:s");
    while ( $sessionqrystmt->fetch() ) {
       if(strtotime($now) > strtotime($dbSessionDate)){
             $class = 'red';
        } else {
             $class = 'green';
        }
        $sessionHTML .= sprintf("<option value='%s' class='%s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), $dbSessionTime) . PHP_EOL;
        }

$now should be the current date and time and $dbSessionDate should be 10-11-2012

UPDATE:

$sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;           

$now = date("Y-m-d H:i:s");
echo strtotime($now).'<br>';
echo strtotime('10-11-2012, 16:00:00');
while ( $sessionqrystmt->fetch() ) {
   if(strtotime($now) > strtotime($dbSessionDate)){
         $class = 'red';
    } else {
         $class = 'green';
    }
    $sessionHTML .= sprintf("<option value='%s' class='%s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
    }


$sessionHTML .= '</select>';

$assessmentform = "<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'>
<p><strong>Assessments:</strong> {$sessionHTML} </p>   
</form>";
  • 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-14T04:44:51+00:00Added an answer on June 14, 2026 at 4:44 am

    The code seems to be OK. Try:

    $now = date("Y-m-d h:i:s");
    echo strtotime($now).'<br>';
    echo strtotime('10-11-2012, 16:00:00');
    

    and check the server time.

    UPDATE:

    Replace:

    $sessionHTML .= sprintf("<option value='%s' class='%s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
    

    with:

    $sessionHTML .= sprintf("<option value='%s' style='color: %s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
    

    to prevent css mistake.

    Or replace:

    strtotime($now) > strtotime($dbSessionDate)
    

    with:

    strtotime($now) < strtotime($dbSessionDate)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JQuery drop down menu which has animated when we hover the
I have a drop down menu which has the following html structure: <ul class=menu>
I have a drop down menu which you can see here on jsfiddle .
I have a drop down menu which fills with some doc names. Now when
I have a drop down menu. Has product types. Product types have associated value
I have a drop down menu, that a user selects a criteria from, based
Currently have a drop down menu that is activated on a hover (from display:none
I have a contact form that has a drop-down for referral source. If Magazine
I have a drop down menu which I found a tutorial for. In Firefox
I have a page with several multiselect drop-down menus. Each menu has a general

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.