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
使用PHP以工作日格式返回给定月份的第一天_Php_Date_Datetime - Fatal编程技术网

使用PHP以工作日格式返回给定月份的第一天

使用PHP以工作日格式返回给定月份的第一天,php,date,datetime,Php,Date,Datetime,因此,为了创建日历,我想确定任何给定月份的第一个工作日是什么。我有以下代码: $today=date('Y-m-d'); IF (!$_GET) { $now=time(); } ELSE { $now=strtotime($_GET['month']); } // the month in question is linked through a GET form variable in the Ymd format

因此,为了创建日历,我想确定任何给定月份的第一个工作日是什么。我有以下代码:

    $today=date('Y-m-d');

    IF (!$_GET) {
    $now=time();
    }
    ELSE {
    $now=strtotime($_GET['month']);
    }

    // the month in question is linked through a GET form variable in the Ymd format

    $thisdaynow=date('Y-m-d', $now);

    $monthyear=date('F Y', $now);

    $thismonth=date('M', $now);

    $thisyear=date('Y', $now);

    $weekday=date('l', $now);

    $firstday = new DateTime($thisdaynow);
    $firstday->modify('first day of this month');
    $work=$firstday->format('Ymd');
    $firstweekday=date('l', $work);
    $firstdayweek=date('w', $work);

    ECHO 'Today is '.$thisdaynow.'<br />';

    ECHO 'The first day of the month was '.$work.'<br />';

    ECHO 'Today is a '.$weekday.'.<br />';

    ECHO 'The first day of this month was a '.$firstweekday.', the '.$firstdayweek.'th day of the week.<br />';
$today=日期('Y-m-d');
如果(!$\u获得){
$now=时间();
}
否则{
$now=strotime($_GET['month']);
}
//所讨论的月份通过Ymd格式的GET form变量链接
$thisdaynow=日期('Y-m-d',$now);
$monthyear=日期('fy',$now);
$thismonth=日期('M',$now);
$thisyear=日期('Y',$now);
$weekday=日期('l',$now);
$firstday=新日期时间($thisdaynow);
$firstday->modify(‘本月第一天’);
$work=$firstday->格式('Ymd');
$firstweekday=日期('l',$work);
$firstdayweek=日期('w',$work);
ECHO“今天是“$thisdaynow”。
; ECHO“月的第一天是“$work”。
; ECHO“今天是一个“$工作日”。
; ECHO“本月的第一天是“$firstweekday”。“$firstdayweek.”是一周的第几天。
这将返回:

今天是2013-05-06

该月的第一天是20130501

今天是星期一

这个月的第一天是星期六,一周中的第六天

这个月有31天

任何关于我做错了什么的帮助都将不胜感激

此代码:

$m = 1;
$d = 1;
$y = 2013;

do {
    $time = strtotime($y.'-'.$m.'-'.$d);
    $month = date('F',$time);
    $dayOfMonth = date('l',$time);
    $totalDays = date('t',$time);
    echo 'First day of '.$month.', '.$y.' is '.$dayOfMonth.' 
          ('.$totalDays.' days in '.$month.').<br />';
} while (++$m < 13);
有关PHP手册的更多信息,请访问:

产生: 星期三

如果问题仍然存在。 问题可能在这里:

IF (!$_GET) {
应该是

if (!isset($_GET['month'])) {
通过这种方式,您总是将分配给当前
时间()
,这就是为什么月份的第一天始终是当前月份的第一天


您的预期输出是什么?对不起,您的代码确实很复杂。美元是多少?带有月份名称的字符串?一个带月数的整数?总是今年吗?新的日期时间(“2013年6月的第一个工作日”)有什么问题?等等。这应该是一个评论。我同意他的代码很凌乱,但在代码中他说$_GET['month']是一个Ymd格式的变量。@mattedgod好吧,5月的第一天是星期三,所以我预计“这个月的第一天是星期三,一周的第四天”,其余的都是正确的,这就是为什么我很困惑的原因。@edwardmp对这个问题没有影响,谢谢你的输入,我真的看不出我的代码和这个函数有什么不同。我的也是星期六生产的。然后,当我检查五月-星期六。和7月-周六。在5月和6月进行测试,并在周三和周六生产。请测试我的代码。它看起来工作正常,是否可以将$getdate格式化为数字0-6(星期日为0)?老实说,这对代码来说比得到当天的名字更重要。我一开始就怀疑$_获取东西,但是$now在我的原始代码中设置正确,所以这不是问题所在。谢谢你的代码截取,我将不得不跳过一些障碍,以获得一个数字工作日,但这比整天盯着我的原始代码好。你可能想再次检查。使用$getdate['wday']进行数字工作日检查以获取更多信息
IF (!$_GET) {
if (!isset($_GET['month'])) {