开发者

php date - check if it's under 1 month

开发者 https://www.devze.com 2023-03-02 00:54 出处:网络
I am checking if a date is less than 1 months from now. I have this working like this $enteredDate < date(\"Ymd\", mktime(0, 0, 0, date(\"m\")+1, date(\"d\"), date(\"y\")))

I am checking if a date is less than 1 months from now. I have this working like this

$enteredDate < date("Ymd", mktime(0, 0, 0, date("m")+1, date("d"), date("y")))

but instead of this big line, I want to put this date("Ymd", mktime(0, 0, 0, date("m")+1, date("d"), date("y"))) inside a function and then just call it to compare $enteredDate < ....

is there any other easy way to do this check. I checked Checkdate but i couldn't use it 开发者_StackOverflow中文版here.

how would I do this by using a function? or should I do the complete check inside a function and use that in places..please give me a hint.


function lessThanOneMonthFromNow($unixTime) {

   return ($unixTime < strtotime('+1 month'));

}


function lessThanOneMonth($date) {

   return (strtotime($date))>(strtotime("-1 month"));

}


Alex's answer is right. But if you want to use your code, just put your code inside a function.

//Returns boolean
function lessThanOneMonthFromNow($enteredDate){
   return $enteredDate < date("Ymd", mktime(0, 0, 0, date("m")+1, date("d"), date("y")));
}

Sample use:

if(lessThanOneMonthFromNow("20110428"))...
0

精彩评论

暂无评论...
验证码 换一张
取 消