我需要得到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
如您所见,'2016-12-31'是我一周开始的日期时间。
提前谢谢!
答案 0 :(得分:3)
似乎很简单,
<?php
$date1 = new DateTime();
$date2 = new DateTime("1969-01-21");
$interval = $date1->diff($date2);
echo ceil($interval->days / 7);
?>