简体   繁体   English

检查日期是否落在日期范围concat与TO运算符之间

[英]check whether a date falls in between date range concat with TO operator

I have following format 2016-06-06 TO 2016-06-12 我有以下格式2016-06-062016-06-12

I want to know that whether my date ie 2016-06-11 lies in between or not. 我想知道我的日期是2016-06-11是否介于两者之间。 How can I do this? 我怎样才能做到这一点?

You can use PHP if condition for checking date range: 如果条件用于检查日期范围,您可以使用PHP:

$compareDate = "2016-06-06 TO 2016-06-12";
$dateArr = explode(" TO ",$compareDate);
$starting_date = $dateArr[0];
$final_date = $dateArr[1];
$date = "2016-06-11";
if($date >= $starting_date && $date <= $final_date) { 
    ...
}
if($date >= $fome_date && $date <= $to_date) 
{   
    echo "yes";
}
else
{
    echo "no";
}

https://3v4l.org/UdIgq https://3v4l.org/UdIgq

i hope it will be helpful 我希望它会有所帮助

Dates can be compared just as numbers can be So using 可以比较日期,因为数字可以如此使用

date > starting_date && date < final_date

Will be just fine for an if clause. if条款就好了。 Also if you have I would recommend you do this in the database part as dbs have built in queries for such occasions. 另外,如果你有,我会建议你在数据库部分执行此操作,因为dbs已针对此类场合内置了查询。

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

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