Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP日期如何检查一周中的哪一天_Php_Date_Datetime - Fatal编程技术网

PHP日期如何检查一周中的哪一天

PHP日期如何检查一周中的哪一天,php,date,datetime,Php,Date,Datetime,我需要创建一个调度程序任务,所以假设我在 `6/24/2014` which is Tuesday the 4th week. 我有今天的约会 `7/27/2014` which is Tuesday the 4th week also 如何在PHP中进行检查,以便如果我检查今天是第4周的星期二,那么可以基于以前的任务创建一个新任务(我有一个复制函数,所以主要问题实际上只是日期部分) e、 g: 另外,假设原始任务是在第5周,那么它将计为该月的最后一周,也就是说,下个月任务将在该月的最后一周

我需要创建一个调度程序任务,所以假设我在

`6/24/2014` which is Tuesday the 4th week.
我有今天的约会

`7/27/2014` which is Tuesday the 4th week also
如何在PHP中进行检查,以便如果我检查今天是第4周的星期二,那么可以基于以前的任务创建一个新任务(我有一个复制函数,所以主要问题实际上只是日期部分)

e、 g:


另外,假设原始任务是在第5周,那么它将计为该月的最后一周,也就是说,下个月任务将在该月的最后一周创建(无论是第4周还是第5周)。

假设您在“该日期是该月的第N个星期二”中计算N时遇到问题

如果您使用
DateTime::format(“d”)
您将返回号码,在本例中为
24
。然后你可以除以7,然后取整

$date1 = new DateTime($a);
$date2 = new DateTime($b);
$days_in_a_week = 7;
$day1 = $date1->format("d");
$day2= $date2->format("d");
$which_week1 = ceil($day1/$days_in_a_week); //4
$which_week2 = ceil($day2/$days_in_a_week); //4
if ($date1->format("D") == $date2->format("D") && $which_week1 == $which_week2) {
    //do stuff
}

假设你只是在“这个日期是一个月的第N个星期二”中计算N有困难

如果您使用
DateTime::format(“d”)
您将返回号码,在本例中为
24
。然后你可以除以7,然后取整

$date1 = new DateTime($a);
$date2 = new DateTime($b);
$days_in_a_week = 7;
$day1 = $date1->format("d");
$day2= $date2->format("d");
$which_week1 = ceil($day1/$days_in_a_week); //4
$which_week2 = ceil($day2/$days_in_a_week); //4
if ($date1->format("D") == $date2->format("D") && $which_week1 == $which_week2) {
    //do stuff
}

假设你只是在“这个日期是一个月的第N个星期二”中计算N有困难

如果您使用
DateTime::format(“d”)
您将返回号码,在本例中为
24
。然后你可以除以7,然后取整

$date1 = new DateTime($a);
$date2 = new DateTime($b);
$days_in_a_week = 7;
$day1 = $date1->format("d");
$day2= $date2->format("d");
$which_week1 = ceil($day1/$days_in_a_week); //4
$which_week2 = ceil($day2/$days_in_a_week); //4
if ($date1->format("D") == $date2->format("D") && $which_week1 == $which_week2) {
    //do stuff
}

假设你只是在“这个日期是一个月的第N个星期二”中计算N有困难

如果您使用
DateTime::format(“d”)
您将返回号码,在本例中为
24
。然后你可以除以7,然后取整

$date1 = new DateTime($a);
$date2 = new DateTime($b);
$days_in_a_week = 7;
$day1 = $date1->format("d");
$day2= $date2->format("d");
$which_week1 = ceil($day1/$days_in_a_week); //4
$which_week2 = ceil($day2/$days_in_a_week); //4
if ($date1->format("D") == $date2->format("D") && $which_week1 == $which_week2) {
    //do stuff
}

如果我正确理解了您的问题,您希望如果在本月的第一、第二、第三周创建任务,则应在下个月的第一、第二、第三周复制该任务。但是,如果它是在本月的最后一周创建的,则应该在下个月的最后一周创建,而不管本月是第4个月还是第5个月

如果是这样,请尝试以下方法:-

$date = "6/24/2014";
$strtotime = strtotime($date);


$array = array(1=>"first",2=>"second",3=>"third",4=>"fourth",5=>"fifth");

$current_month = date('n',$strtotime);
$day_num = date('d',$strtotime);
$day_word = date('l',$strtotime);
$next_month = date('F',strtotime('next month',$strtotime));
$next_week_month = date('n',strtotime('next '.$day_word, $strtotime));
$num_of_days = date('t',$strtotime);

$week = ceil($day_num/7);

$word = $array[$week];

if($next_week_month > $current_month){
    $word = 'last';
}

echo date('m/d/Y', strtotime($word.' '.$day_word.' of '.$next_month.' 2014')); //Outputs 2014-07-29
此外,此脚本还会检查当前日期是否为本月的最后一天。例如:-


2014年6月24日是最后一个星期二,但是第4周,6月有5周。

如果我正确理解了您的问题,您希望如果任务在本月的第一、第二、第三周创建,则应在下个月的第一、第二、第三周复制。但是,如果它是在本月的最后一周创建的,则应该在下个月的最后一周创建,而不管本月是第4个月还是第5个月

如果是这样,请尝试以下方法:-

$date = "6/24/2014";
$strtotime = strtotime($date);


$array = array(1=>"first",2=>"second",3=>"third",4=>"fourth",5=>"fifth");

$current_month = date('n',$strtotime);
$day_num = date('d',$strtotime);
$day_word = date('l',$strtotime);
$next_month = date('F',strtotime('next month',$strtotime));
$next_week_month = date('n',strtotime('next '.$day_word, $strtotime));
$num_of_days = date('t',$strtotime);

$week = ceil($day_num/7);

$word = $array[$week];

if($next_week_month > $current_month){
    $word = 'last';
}

echo date('m/d/Y', strtotime($word.' '.$day_word.' of '.$next_month.' 2014')); //Outputs 2014-07-29
此外,此脚本还会检查当前日期是否为本月的最后一天。例如:-


2014年6月24日是最后一个星期二,但是第4周,6月有5周。

如果我正确理解了您的问题,您希望如果任务在本月的第一、第二、第三周创建,则应在下个月的第一、第二、第三周复制。但是,如果它是在本月的最后一周创建的,则应该在下个月的最后一周创建,而不管本月是第4个月还是第5个月

如果是这样,请尝试以下方法:-

$date = "6/24/2014";
$strtotime = strtotime($date);


$array = array(1=>"first",2=>"second",3=>"third",4=>"fourth",5=>"fifth");

$current_month = date('n',$strtotime);
$day_num = date('d',$strtotime);
$day_word = date('l',$strtotime);
$next_month = date('F',strtotime('next month',$strtotime));
$next_week_month = date('n',strtotime('next '.$day_word, $strtotime));
$num_of_days = date('t',$strtotime);

$week = ceil($day_num/7);

$word = $array[$week];

if($next_week_month > $current_month){
    $word = 'last';
}

echo date('m/d/Y', strtotime($word.' '.$day_word.' of '.$next_month.' 2014')); //Outputs 2014-07-29
此外,此脚本还会检查当前日期是否为本月的最后一天。例如:-


2014年6月24日是最后一个星期二,但是第4周,6月有5周。

如果我正确理解了您的问题,您希望如果任务在本月的第一、第二、第三周创建,则应在下个月的第一、第二、第三周复制。但是,如果它是在本月的最后一周创建的,则应该在下个月的最后一周创建,而不管本月是第4个月还是第5个月

如果是这样,请尝试以下方法:-

$date = "6/24/2014";
$strtotime = strtotime($date);


$array = array(1=>"first",2=>"second",3=>"third",4=>"fourth",5=>"fifth");

$current_month = date('n',$strtotime);
$day_num = date('d',$strtotime);
$day_word = date('l',$strtotime);
$next_month = date('F',strtotime('next month',$strtotime));
$next_week_month = date('n',strtotime('next '.$day_word, $strtotime));
$num_of_days = date('t',$strtotime);

$week = ceil($day_num/7);

$word = $array[$week];

if($next_week_month > $current_month){
    $word = 'last';
}

echo date('m/d/Y', strtotime($word.' '.$day_word.' of '.$next_month.' 2014')); //Outputs 2014-07-29
此外,此脚本还会检查当前日期是否为本月的最后一天。例如:-



2014年6月24日是最后一个星期二,但是第4周,6月有5周。

你的意思是2014年7月29日是星期二,现在是第5周。只要看一下文件,evrything就在…@Samosa no,我的意思是如果它是在6月24日创建的,也就是第4周,那么它应该在第4周创建你的意思是2014年7月29日是星期二,是第5周。只要看一下文件,evrything就在…@Samosa不,我的意思是如果它是在第4周的6月24日创建的,那么它应该在第4周创建你的意思是2014年7月29日是星期二,是第5周。只要看一下文件,evrything就在…@Samosa不,我的意思是,如果它是在6月24日(第4周)创建的,那么它应该在第4周创建。你的意思是2014年7月29日是星期二,现在是第5周。只要看一下文档,所有东西都在…@Samosa不,我的意思是如果它是在6月24日(第4周)创建的,然后它应该在第4周创建,虽然我需要定制一点,但我需要的是Tootis。但是$which_week1和$which_week2应该是ceil而不是max。修复它,我将把它标记为一个答案。如果只给出一个输入,max input不应该是数组吗?这正是我需要的,尽管我需要对它进行一点自定义。但是$which_week1和$which_week2应该是ceil而不是max。修复它,我将把它标记为一个答案。如果只给出一个输入,max input不应该是数组吗?这正是我需要的,尽管我需要对它进行一点自定义。但是$which_week1和$which_week2应该是ceil而不是max。修复它,我将把它标记为一个答案。如果只给出一个输入,max input不应该是数组吗?这正是我需要的,尽管我需要对它进行一点自定义。但是$which_week1和$which_week2应该是ceil而不是max。修复它,我将它标记为一个答案。如果只给出1个输入,max input不应该是数组吗?