2017-10-07 179 views
0

中的日期我在这里有一个小混乱。在我的项目中,我需要按日期显示房间价格。例如 。 2017年10月1日至2017年10月31日的 价格为200美元。 从01st 11月 - 11月30日的价格为$ 250等等.....如何实现大于或小于php

现在我试图做这样....

 <?php 

      $currnt_time = time(); 
      $from_date = strtotime(2017-10-01); 
      $till_date = strtotime(2017-10-31); 

      if ($currnt_time >= $from_date && $currnt_time < $till_date){ 
       $price = $200; 
      } 

      ?> 
      <P> Starts FROM <?php echo $price; ?> INR</P> 

但是当我运行此脚本它说未定义的变量$ price。我不明白我错在哪里),因为我会有像上面这样的日期槽,所以最好的解决方法是什么。 请帮忙。谢谢 !

+0

比我asume来自片断的编辑一些语法错误其它,它[应该工作(https://3v4l.org/jloJ2) – ishegg

回答

1

您在$price的值前面有一个$,并且您已经习惯于在日期字符串之前和之后添加报价。

<?php 
    $currnt_time = time(); 
    $from_date = strtotime('2017-10-01'); 
    $till_date = strtotime('2017-10-31'); 

    if ($currnt_time >= $from_date && $currnt_time < $till_date){ 
     $price = 200; 
    } 

    ?> 
    <P> Starts FROM <?php echo $price; ?> INR</P> 
?> 
+0

谢谢!工作......小混乱......哪个日期总是过去或未来更大? – kohali

+0

又一个小问题我如何动态地把年份而不是象2017年那样硬编码....因为在上述情况下,我需要每年更改我的代码..任何解决方案,请 – kohali

+0

使用PHP的日期。日期( 'Y'); – Akintunde007