strtotime正常工作-60天

时间:2016-11-24 09:33:12

标签: php strtotime

我正在尝试比较两个日期,但是由于某些原因我看起来使用-60天不能用于strtotime。

$date =  date('Y-m-d H:i:s', strtotime("-60 days")); // gives me string) 2016-09-25 09:27:26
$today_dt = strtotime($date);
$expire_dt = strtotime($result['insertedInvoice']); // insertedInvoice shows 2016-11-24 08:56:48

if( $today_dt > $expire_dt){
 dothis();
}else{
  dothat();
}

问题在于,在这个函数中它应该用于dothis();,而是用于dothat();因为$ today_dt落后60天,所以它不能超过$ expire_dt。

3 个答案:

答案 0 :(得分:1)

请尝试以下

$now = date('Y-m-d H:i:s');

$date =  date('Y-m-d H:i:s', strtotime('-60 days', strtotime($now)));
$today_dt = strtotime($date);
$expire_dt = strtotime($result['insertedInvoice']); // insertedInvoice shows 2016-11-24 08:56:48

if( $today_dt > $expire_dt){
 dothis();
}else{
  dothat();
}

**我根据您的代码编写此代码,请检查 if 条件。如果需要,请按以下方式更改 if 条件 (我对你的最后一句话感到有些困惑)

if( $today_dt < $expire_dt){
   dothis();
} else {
   dothat();
}

答案 1 :(得分:1)

您可以改为使用DateTime:

//Single/First match expected: use no global modifier and access match[1]
console.log("My cow always gives milk".match(/cow (.*?) milk/)[1]);
// Multiple matches: get multiple matches with a global modifier and 
// trim the results if length of leading/trailing delimiters is known
var s = "My cow always gives milk, thier cow also gives milk";
console.log(s.match(/cow (.*?) milk/g).map(function(x) {return x.substr(4,x.length-9);}));
//or use RegExp#exec inside a loop to collect all the Group 1 contents
var result = [], m, rx = /cow (.*?) milk/g;
while ((m=rx.exec(s)) !== null) {
  result.push(m[1]);
}
console.log(result);

答案 2 :(得分:0)

protected void Timer2_Tick(object sender, EventArgs e)
{
    Timer2.Enabled = false;
    Session.Clear();
    Session.Timeout = 1;
    Session.RemoveAll();
    Session.Abandon();
    Response.Redirect("~/TestPage.aspx");
}