PHP是其他日期之间的日期 - 忽略月份 [英] PHP is date between 2 other dates - Ignoring month

查看:97
本文介绍了PHP是其他日期之间的日期 - 忽略月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定一天和两天是否在两个人之间,我有以下...

  $ 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 c c c c c c c

I am trying to determine if a day and time are between two others, I have the following...

$currentdate = date("N h:i:s A");

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 $currentdate is between 9am on a Friday and 9am on a Monday.

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 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;

  }

}

Just removed the extra if statement as it was not needed

这篇关于PHP是其他日期之间的日期 - 忽略月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆