2015-04-19 41 views
2
if ((strtotime("1 June") == time())) 
{ 
    mysql_connect("localhost","root","");//database connection 

    mysql_select_db("student"); 

    $order = "UPDATE stud SET class='9' WHERE class='8'"; 

    $result = mysql_query($order); //order executes 
} 

上面的代码不work..i改变了我的日期1周june..but的strtotime()和时间()返回的值不同..我怎么能检查当前日期的日期

+0

时间通过计算当前日期为您提供价值,这就是为什么它不会给你同样的价值,因为你想。 –

回答

1
$cmp = strtotime("19 April"); 

// convert specified date to int 
$current_date = strtotime(date("Y-m-d")); 


if ($cmp == $current_date) { 
    // process 
} 

时间()函数将让你和你的

strtotime(date('Y-m-d H:i:s')); 

等价的,如果要比较当前日期和时间给出仅使用

strtotime(date('Y-m-d')); 

,这将使结果的

格式
strtotime("19 April"); 

检查文件的时间和日期 http://php.net/manual/en/function.strtotime.php

+0

为什么你会使用'date()'函数来获取今天的日期?为什么不在'strtotime()'中使用'today'关键字?像这样[示例](https://eval.in/315515)。 –

+1

是的,它可以..所有的人有不同的方式来解决问题。感谢那..链接 –

相关问题