简体   繁体   English

与PHP中的日期比较

[英]comparing to date in PHP

hi guys I am dealing with this problem! 嗨,我正在处理这个问题! it is hard for me! 对我来说很难! I really need help with this, this is what you will be see in the UI, 我真的需要帮助,这就是您将在UI中看到的内容,

   Date Availing the Reservation: 9/12/2016(current date)
   Date Needed: mm/dd/yyyy
   Date of the Event: 9/26/2016(date 2 weeks from now)
   Date Reservation will Expire: 9/15/2016

What i want is that when the Date Needed is less than the current date it will show date should not be from the past, and if Date Needed is equal to date now until the date of the event which is 26 i am only valid to avail at 27 how will i do that? 我想要的是,当需要的日期小于当前日期时,它将显示日期不应该是过去的日期,并且如果需要的日期等于现在的日期,直到事件发生的日期是26,则我仅是有效的在27岁时我该怎么做? i have this logic: 我有这个逻辑:

   if($date_needed < $date_reserved &&  $date_needed > $date_of_the_event){
     echo "date must not be from the past and date of reservation must be 2 weeks from now";
   }
   else{
     echo "success!";
   }

This code didn't work well for me I mean, if I have this code, even thought I am putting the right code, it always comes up with error, i even else if this logic but it isn't working at all. 这段代码对我来说不是很好,我的意思是,如果我拥有此代码,甚至以为我输入了正确的代码,它总是会出错,即使这种逻辑也无法正常工作,我还是会出错。 can you help me with this? 你能帮我吗? and my 2nd question is, I have this at my database: Date Reservation will Expire. 我的第二个问题是,我的数据库中有这个:日期保留将过期。 I want if that day will come 9/15/2016. 我想那一天是2016年9月15日。 The row which has it, will automatically be deleted at the database or update it that is_active will be 0 how will I do that? 包含该行的行将自动在数据库中删除或更新,即is_active将为0怎么办? thank you so much for the help. 非常感谢你的帮助。

For Client Side validation please review example : http://keith-wood.name/uidatepickervalidation.html 对于客户端验证,请查看示例: http : //keith-wood.name/uidatepickervalidation.html

For Server Side 对于服务器端

Ans 1: Simple way is convert dates in time and check how many days are left 答案1:简单的方法是及时转换日期并检查还剩多少天

$now = time();  //current date - Date Availing the Reservation
$your_date_needed = strtotime(date('YYYY-MM-DD'));
$datediff = $your_date_needed - $now;
$daysLeft = round($datediff/(60*60*24));
if($daysLeft>0) {
    echo "success! ".$daysLeft;
} else {
    echo "date should not be from the past";
}

Ans 2: You need to create a php file with same logic and then you can use Cron Job 回答2:您需要使用相同的逻辑创建一个php文件,然后才能使用Cron Job

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM