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

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

$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.'
';

ECHO 'The first day of the month was '.$work.'
';

ECHO 'Today is a '.$weekday.'.
';

ECHO 'The first day of this month was a '.$firstweekday.', the '.$firstdayweek.'th day of the week.
';

这会返回:

Today is 2013-05-06

The first day of the month was 20130501

Today is a Monday.

The first day of this month was a Saturday, the 6th day of the week.

There are 31 days this month.

对我所做错的任何帮助都将不胜感激!!!

解决方法:

$inputMonth = '2013-05-01';

$month = date("m" , strtotime($inputMonth));

$year = date("Y" , strtotime($inputMonth));

$getdate = getdate(mktime(null, null, null, $month, 1, $year));

echo $getdate["weekday"];

生产:

星期三

如果问题仍然存在.

问题可能在这里:

IF (!$_GET) {

应该

if (!isset($_GET['month'])) {

这样,您总是分配当前时间(),这就是为什么月份的第一天始终是当前月份的原因.

标签:php,datetime,date

来源: https://codeday.me/bug/20190825/1721490.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值