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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:49:06+00:00 2026-06-06T11:49:06+00:00

Like the title says, PHP is really confusing me on a simple if comparison

  • 0

Like the title says, PHP is really confusing me on a simple if comparison statement that’s returning the opposite of what it should be returning. I’m trying to compare 2 datetime’s that are first converted to strings:

//Fetched db query, this returns 2012-06-23 16:00:00
$databaseDateTime = strtotime($row['time']);
//This now returns 1340481600

//today's date and time I'm comparing to, this returns 2012-06-22 17:14:46 
$todaysDateTime = strtotime(date("Y-m-d H:i:s"));
//this now returns 1340399686

Great, everything works perfect so far. Now here’s where things get hairy:

if ($databaseDateTime < $todaysDateTime) { $eventType = 'past'; }

And this returns ‘past’, which of course it shouldn’t. Please tell me I’m missing something. My project kind of depends on this functionality being airtight.

**EDIT***
Thanks guys for taking the time to help me out. Let me post the entire code because a few of you need more context. The request is coming from an IOS5 to my backend code and json is being sent back to the phone.

<?php
 //all included files including $link to mysqli_db and function sendResponse()

 function getEvents($eventType, $eventArray) {
   global $link;
   global $result;
   global $i;
   global $todaysDateTime;
   foreach ($eventArray as $key => $value) {
       $sqlGetDeal = mysqli_query($link, "SELECT time FROM deals WHERE id='$value' AND  active='y' LIMIT 1") or die ("Sorry there has been an error!");

    while ($row = mysqli_fetch_array($sqlGetDeal)) {

       //compare times to check if event already happened
       $databaseDateTime = strtotime($row['time']);
       if ($databaseDateTime < $todaysDateTime) { $eventType = 'past'; }

      $result[$i] = array(
        'whenDeal' => $eventType,
        'time' => $databaseDateTime,
      );
      $i++;
    }//end while

  }//end foreach
 }

 if (isset($_GET['my'])) {
   //$_GET['my'] comes in as a string of numbers separated by commas e.g. 3,2,6,3
   $myDeals = preg_replace('#[^0-9,]#', '', $_GET['my']);
   $todaysDateTime = strtotime(date("Y-m-d H:i:s"));
   $result = array();

   $kaboomMy = explode(",", $myDeals);

   $i = 1;
   if ($myEvents != "") {
     getEvents('future', $kaboomMy);
   }//end if

   sendResponse(200, json_encode($result));

 } else {
   sendResponse(400, 'Invalid request');
 } //end $_POST isset

?>
  • 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-06T11:49:08+00:00Added an answer on June 6, 2026 at 11:49 am

    Found a quick hack around the issue. I just added a local variable to my function and rearranged my compare statement

    //added local variable $eventTyppe to function
    $eventTyppe;
    

    changed compare from:

     if ($databaseDateTime < $todaysDateTime) { $eventType = 'past'; } 
    

    to:

    if ($todaysDateTime < $databaseDateTime ) { 
         $eventTyppe = $eventType; 
      } else { 
         $eventTyppe = 'past'; 
      }
    

    Notice if I rearrange compare:

    if ($databaseDateTime < $todaysDateTime ) { 
       $eventTyppe = 'past'; 
     } else { 
       $eventTyppe = $eventType; 
     }
    

    I still get the same error. This is the weirdest thing I’ve ever seen and the first PHP bug I’ve run into (I’m assuming it’s a PHP bug).

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

Sidebar

Related Questions

Like the title says, I'm trying to determine if data is a standard attribute
So, just like the title says, I need to create an application that gets
The title pretty much says it all. If I have something like (from PHP
Like the title says, I need to use php (wordwrap or whatever works) to
as the title said i would like to create a button that says available
Just like the title says here is a sample of the command that I'm
Title says all. I'll have navigation that looks like this and it's dynamically created
like the title says, I am trying to create a drop down menu using
Like the title says, I need a way to detect if the build is
so basically like the title says is there a way to use NSSortDescriptor to

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.