PHP是其他日期之间的日期 - 忽略月份 [英] PHP is date between 2 other dates - Ignoring month
问题描述
我正在尝试确定一天和两天是否在两个人之间,我有以下...
$ currentdate = date(N h:i:s A);
将一周中的日期作为一个数字返回,然后以24小时格式返回当前时间。 / p>
我想查看 $ currentdate
是在星期五上午9点和星期一上午9点之间。 >
最好的解决方法是什么?
我相信这应该给你你的要求,但我相信有更好的方法来实现。因此,基本上将时间转换为 INT
进行比较,并将时间配置为不具有前导零,因此为什么 $ timeOne
和 $ timeTwo
较短。如果语句在那个特定的日期测试日期和时间,那么我就使用了一个,只要满足条件,就可以添加一个插槽来添加代码。
function checkDayTime(){
$ day = date(w); // 0(星期日)到6(星期六)
$ timeOne = 90000;
$ timeTwo = 90000; //添加更容易阅读
$ currentTime =(int)date('Gis'); // Time as INT 00000> 240000
if(($ day == 5&& $ currentTime> $ timeOne)||($ day == 6 || $ day == 0)|| ($ day == 1&& $ currentTime< $ timeTwo)){
//在这些小时之间
return TRUE;
} else {
//不在那些小时之间
返回FALSE;
}
}
如果 c I am trying to determine if a day and time are between two others, I have the following... This returns the day of the week as a number and then the current time in 24 hour format. I want to check if the What is the best way to tackle this? I believe this should give you what your asking for but I'm sure there are better ways to implement. So basically the time has been converted into an Just removed the extra 这篇关于PHP是其他日期之间的日期 - 忽略月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!$currentdate = date("N h:i:s A");
$currentdate
is between 9am on a Friday and 9am on a Monday.INT
for comparing and the hours are configured not to have a leading zero hence why $timeOne
and $timeTwo
is shorter. I've then used an if
statement to test days and time on that specific day leaving you a slot to add your code if those conditions are met.function checkDayTime() {
$day = date(w); //0 (for Sunday) through to 6 (for Saturday)
$timeOne = 90000;
$timeTwo = 90000;//Added for easier reading
$currentTime = (int) date('Gis'); //Time as INT 00000 > 240000
if (($day == 5 && $currentTime > $timeOne) || ($day == 6 || $day == 0) || ($day == 1 && $currentTime < $timeTwo)) {
//Between those hours
return TRUE;
} else {
//Not between those hours
return FALSE;
}
}
if
statement as it was not needed