[英]PHP: Get week number starting by 1969 year
I need to get the actual week number starting by 1969 year like this: 我需要这样获得1969年之前的实际周数:
$dateTime = new DateTime;
$now = '2017-01-01';
//
// $week = date('W', strtotime($now . ' +2 days'));
// I will get the week number between 01-53 and this is not what I want.
// I need to set the starting year and get the week number since 1969 to get the expected results.
// How to get the value 2506 from this $week variable?
//
$dateTime->setISODate('1969', 2506, -1);
$start_by = $dateTime->format('Y-m-d');
// output: 2016-12-31
As you can see, the '2016-12-31' is the datetime of my week start. 如您所见,“ 2016-12-31”是我一周开始的日期时间。
Thank you in advance! 先感谢您!
Seems simple, 看起来很简单,
<?php
$date1 = new DateTime();
$date2 = new DateTime("1969-01-21");
$interval = $date1->diff($date2);
echo ceil($interval->days / 7);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.