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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:51:20+00:00 2026-06-08T10:51:20+00:00

These are the inputs an database rows $current 2012-07-26 15:30:00 1st $row[‘start’] 2012-07-26 14:00:00

  • 0

These are the inputs an database rows

$current              2012-07-26 15:30:00
1st $row['start']     2012-07-26 14:00:00
2nd $row['start']     2012-07-26 17:00:00

When I run the following code with the above current time, I get correctly the “Starts soon” for the 2nd row, but also I get it mistakenly on the 2nd row that it already started.

How do I edit this code to return me the “Starts soon” message only to the rows that will start in the next two hours?

$diff = strtotime($row['start']) - strtotime($current);
if ($diff < 7200) {
    echo 'Starts soon';
} else if ($diff <= 0) {
    echo 'Started';
} else {
    echo 'Starts';
}
  • 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-08T10:51:22+00:00Added an answer on June 8, 2026 at 10:51 am

    All $diff matching your second if clause (< 0) are already caught by the first if clause (< 7200) and never reach the second if in that else clause.

    As a solution, restructure your code in the following way:

    $diff = strtotime($row['start']) - strtotime($current);
    if ($diff <= 0) {
        echo 'Started';
    } else if ($diff < 7200) {
        echo 'Starts soon';
    } else {
        echo 'Starts';
    }
    

    EDIT

    With respect to the question in comments:

    If you mean the calendar day, you could use the following code:

    if ( date( 'zY', $current ) == date( 'zY', $row['start'] ) {
      // same day
    } else {
      // different days
    }
    

    If you mean just that both times are no more than 24 hours apart, use

    if ( abs($current - $row['start']) < 24 * 60 * 60 ) {
      // same day
    } else {
      // different day
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 46 rows of information, 2 columns each row (Code Number, Description). These
I have these text inputs in a table : <td><input type='text' name='arrondi_devis_ht' class='calcul_total' size='8'></td>
I have a table with a lot of text inputs like these: alt text
These tools basically input a grammar and output code which processes a series of
I have a form that uses jquery to generate rows of input fields these
I made a class. I give it some objects (mostly retreived database rows) as
I want to run a query on an Oracle database and for each column
I have a series of parameters stored in rows in the database, and I'd
Given an input string, I'd like to return the rows from a (MySQL) database
I have an MEMORY MYSQL database that contains a table with 200k+ rows. I

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.