kjtocool Posted January 11, 2008 Share Posted January 11, 2008 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 More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 if ($todays_date < $prediction deadline) Why is there a gap between $prediction and dealine? I think that's why. Link to comment https://forums.phpfreaks.com/topic/85557-date-comparison-not-working/#findComment-436600 Share on other sites More sharing options...
kjtocool Posted January 11, 2008 Author Share Posted January 11, 2008 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 https://forums.phpfreaks.com/topic/85557-date-comparison-not-working/#findComment-436603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.