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

  • Home
  • SEARCH
  • 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 8423755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:48:42+00:00 2026-06-10T03:48:42+00:00

I have the php code below comparing two times against the current time using

  • 0

I have the php code below comparing two times against the current time using strtotime:

 $timingsfirstTime[0] = date("H:i:s", strtotime(trim($showTimings[0])));
 $timingslastTime[2] = date("H:i:s", strtotime(trim($showTimings[2])));

// Confirm that the start time of the frist show is greater than the last time of last show on the channel

        $current_time = date("H:i:s",strtotime('now'));

        $this->assertTrue(($current_time > $timingsfirstTime[0] && $current_time < $timingslastTime[2]),"current time ".$current_time. " is not greater than current show start time ". $timingsfirstTime[0] . " or current time is not less than current show end time ".$timingslastTime[2]); 

But my the assertion fails somehow and outputs:

current time 00:38:45 is not greater than current show start time 23:50:00 or current time is not less than current show end time 00:50:00

  • 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-10T03:48:43+00:00Added an answer on June 10, 2026 at 3:48 am

    You’re doing string comparisons, not date comparisons, which is why it’s “failing”.

    Use DateTime instead, since it’s easier to read, less code, and can be compared natively. I would also split your assertion into two assertions to make it easier to tell what case failed:

    $now = new DateTime();
    $start = new DateTime($showTimings[0]);
    $end = new DateTime($showTimings[2]);
    
    $this->assertTrue(
        $now > $start,
        'current time ' . $now->format('H:i:s')
            . ' is not greater than current show start time '
            . $start->format('H:i:s')
    );
    
    $this->assertTrue(
        $now < $end,
        'current time ' . $now->format('H:i:s')
            . ' is not less than current show end time '
            . $end->format('H:i:s')
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I have some php code below, where I'm using foreach. <div class=carousel-inner> <?php if(count($items)):
I have a basic PHP question, take the code below for example, let's say
I have a real basic form (code below) with a bunch of back-panel PhP.
I have a php code below where it is suppose to display my buttons,
I have a simple html file with the code below. It calls submitform.php. But
I have the PHP code below. It is supposed to select up to ten
I have php code similar to this below: foreach ($questions as $q){ foreach ($answers
I have the php code below which help me get a photo's thumbnail image
I have the following php code below... if ($username == 'fredk') { $fname =

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.