[英]How to find week number of a day in a month using php
hai i found this PHP get number of week for month quiet helpful but it makes some error on all months start on Sundays for example "2013-09-01" gives week number as 2 (actually its '1').. any one got some idea?? hai,我发现此PHP获得月度安静的星期几很有帮助,但在周日开始的所有月份中都会出错,例如,“ 2013-09-01”将周数设为2(实际上是“ 1”)。一些想法? please share thanks in advance.....
请提前分享感谢.....
use date("W","2013-09-01");
使用
date("W","2013-09-01");
.it will return week number as 01. .it将返回第01周。
向其添加strtotime函数。工作正常.. date(“ W”,strtotime(“ 2013-09-01”));
This utility function returns the week of the month for a specific day. 该实用程序函数返回特定日期的每月的星期。 Needs two args: the wanted day, and the first day of the same month
需要两个参数:通缉日和同一月的第一天
class WeekCalculator
{
public static function getWeekOfMonth($date, $firstDayOfMonth) {
$w1 = date("W", $firstDayOfMonth->getTimestamp());
$w2 = date("W", $date->getTimestamp());
$weekNum = $w2 - $w1 + 1;
return $weekNum;
}
}
Example usage 用法示例
WeekCalculator::getWeekOfMonth(new \DateTime('2016-8-8'), new \DateTime('2016-8-1'));
Returns 2 (second week of August 2016) 返回2(2016年8月的第二周)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.