Php 如何使用我的表中的日期获取并减去当前日期时间

Php 如何使用我的表中的日期获取并减去当前日期时间,php,mysql,sql,Php,Mysql,Sql,我在这个网站上定义了动物变老的年龄。如果我定义6岁是动物变老的年龄,我想更新我的表格,作为动物的出生日期,所有处于这种情况的动物都变老。我在varchar中有数据字段,因为in Date is给了我一些问题 $variable = $_POST['age']; **Here I am receiving the date I define in previous page** if($variable == null){ ?> <script> ale

我在这个网站上定义了动物变老的年龄。如果我定义6岁是动物变老的年龄,我想更新我的表格,作为动物的出生日期,所有处于这种情况的动物都变老。我在varchar中有数据字段,因为in Date is给了我一些问题

$variable = $_POST['age']; **Here I am receiving the date I define in previous page**
if($variable == null){
     ?>
    <script>
    alert("Please choose an age");
    self.location="Definitions.php";
</script>


    <?php

}

**I need also to retrieve the actual system date**

if(isset($_POST['submit_x'])) **This is the id from previous page**
{    
        $query="update animal set old = '1' where chipnumber = {$var} AND user_id = {$_SESSION['user_id']}...."; **I need to complete my query in order to update only in the animals with the age I defined**
        mysqli_query($con, $query) or die (mysql_error());
应该以这种方式进行修改。
或者更好的方法是创建一个表行作为UI接口。您不必为old或not再创建一个字段。因为旧国旗是由年龄决定的。旧列变得多余

注意,$variable!=$变量和mysql_错误不适用于mysqli_查询是否应为die mysqli_error$conIf您的chipnumber数据字段?是varchar,那么您需要将您的值视为字符串并引用它,即。。。其中chipnumber='{$variable}'。。。。另外,是时候仔细阅读了,以确保您的$variable不会导致sql injectionquestion的方式太不明确。检查错误,你有一些错误。
  $query="update animal set old = '1' where chipnumber = '".$_POST['var']."' AND user_id = '".$_POST['id']."' ... ;