Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查当前日期是否大于';储存的_Php_Mysql - Fatal编程技术网

Php 检查当前日期是否大于';储存的

Php 检查当前日期是否大于';储存的,php,mysql,Php,Mysql,因此,目前的问题是代码工作正常,但是第二个月重置id从5月到6月,代码将不再工作,因为它正在寻找是否更大,并且由于第1个月不大于第31个月,它有一个问题,它不看月份或年份,只看当天 示例:数据库将2016年5月31日存储为$reward。 在本例中,2016年6月3日的输出为$current <?php $reward1 = str_replace('/', '-', $reward); $stored = date('d/m/Y', strtotime($

因此,目前的问题是代码工作正常,但是第二个月重置id从5月到6月,代码将不再工作,因为它正在寻找是否更大,并且由于第1个月不大于第31个月,它有一个问题,它不看月份或年份,只看当天

示例:数据库将2016年5月31日存储为$reward。 在本例中,2016年6月3日的输出为$current

  <?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 } } ?>

$(窗口)。加载(函数(){
$('1')。模态('show');
});

您正在比较字符串。这是错误的

查看优秀的碳库,了解实现这一目标的最佳实践


我认为您的代码中有一些错误,如上面在评论中发布的。
看看它是否有效

$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 } } ?>
$reward1=str_replace(“/”、“-”、$reward);
$stored=STROTIME(日期('d-m-Y',STROTIME('reward1.'+1天'));
$current=strottime(日期('d-m-Y'));
//现在两个值都是整数
//使用d/m/y不是标准的日期时间,php假定它是美国的m/d/y。
如果($stored<$current){?>
$(窗口)。加载(函数(){
$('1')。模态('show');
});

如果strotime值大于日期时间字符串,则您正在签入。strotime是一个整数值,字符串是一个字符串。请尝试以下操作:
if($redward
很抱歉,您正在根据字符串检查字符串。执行此操作:
if(strotime($redward)
现在这两个值都是整数和秒,因为1970年以后,$reward也变成$reward1,变成$stored,然后在if中使用$reward(第一个值)。这不应该是$stored吗?如果需要比较日期字符串,它们的格式应该是“yyyy\mm\dd”-先是年,然后是2位数的月,然后是2位数的日。但正如其他人所说,最好将日期转换为整数值。如果使用“Ymd”和intval,则可以将日期作为字符串进行比较,因为数字在以后的日期总是会更高。但是strotime要好得多。我使用了注释中的代码并修复了存储的$(不知道我是怎么把事情搞得这么糟的!但非常感谢你的评论修复了它!:)没问题。有时你需要后退一步才能看到明显的错误,例如使用了错误的变量。对我来说也发生过几次。:-)@UKTSLiam也不考虑我在这里的代码中对d/m/y日期的评论。如果你继续使用它,可能会再次引起问题。我将看一看如何交换:)谢谢。
$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 } } ?>