UKTSLiam UKTSLiam - 6 months ago 14
SQL Question

Issue with checking if current date is bigger than what's stored

So the issue currently is the code works fine, however the second the month resets id goes from May to June the code will no longer work because It's looking for if it's greater, and as 1st is not greater than 31st it has an issue, it's not looking at the month or year, just the day..

EXAMPLE: Database stores 31/05/2016 as $reward.
In this example $current would output at 03/06/2016

<?php
$reward1 = str_replace('/', '-', $reward);
$stored = date('d/m/Y', strtotime($reward1. ' + 1 days'));
$current = date('d/m/Y');
if ($reward < $current) { ?>
<script type="text/javascript">
$(window).load(function(){
$('#redeem1').modal('show');
});
</script>

<?php } } ?>

Answer

I think there is a few errors in your code as posted above in comments.
See if it works.

$reward1 = str_replace('/', '-', $reward);
$stored = strtotime(date('d-m-Y', strtotime($reward1. ' + 1 days')));
$current = strtotime(date('d-m-Y'));

// now both values are in integer
// using d/m/y is not a standard datetime, php assumes it is american m/d/y. 
   if ($stored < $current) { ?>
     <script type="text/javascript">
       $(window).load(function(){
           $('#redeem1').modal('show');
       });
     </script>

 <?php } } ?>
Comments