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
https://forums.phpfreaks.com/topic/85557-date-comparison-not-working/
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";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.