Jump to content

Date Comparison not working


kjtocool

Recommended Posts

I am trying to compare two dates like so:

 

<?php
if ($todays_date < $prediction_deadline) {
  echo "do this";
}
else {
  echo "do that";
}
?>

 

I have echoed out both variables at before the comparison, and have done so at various different times.  Below is some of the times I've echoed the variable out, and the comparison's result:

 

Today's Date: 2008-01-11 03:17:46 vs Prediction Deadline: 2008-01-11 05:01:00

- Comparison prints "do that"

 

Today's Date: 2008-01-11 01:22:14 vs Prediction Deadline: 2008-01-11 04:01:00

- Comparison prints "do that"

 

Today's Date: 2008-01-11 12:23:56 vs Prediction Deadline: 2008-01-11 10:01:00

- Comparison prints "do that"

 

Today's Date: 2008-01-11 12:24:54 vs Prediction Deadline: 2008-01-11 12:29:00

- Comparison prints "do this"

 

Today's Date: 2008-01-11 12:26:17 vs Prediction Deadline: 2008-01-11 14:29:00

- Comparison prints "do this"

 

I don't understand why the first two comparisons are coming up faulty?  Could it be because of the 0 before the hour?

Link to comment
Share on other sites

Nah, this is just code I wrote to simplify and explain the issue, the real code is much more complicated, but working. 

 

As I said, some comparisons work correctly, others do not.

 

It should also be noted that the time is stored in a mysql databae by the following:

 

<?php
// Gives the date
$prediction_end = $_POST['prediction_end'];
// Adds the time
$prediction_end .= " 04:01:00";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.