php从特定日期查找周数

时间:2011-08-28 21:02:11

标签: php date

我想从特定的开始日期找到特定的周数。例如,从数据库中拖动$ date(即07/08/2011)

我希望这是开始日期,因此从这一天起它将是第3周。这是我到目前为止的代码,但只显示了ISO版本:

    $date = strtotime("".$row['start_date'].""); 
$weekNumber = date("W", $date); 
print $weekNumber;

我用Google搜索了两个小时,但似乎无法找到解决此问题的任何内容!任何帮助都会非常感谢!

2 个答案:

答案 0 :(得分:1)

获取now和startdate之间的差异,然后除以7天(7 * 86400秒)

<?php
    $startdate = strtotime("".$row['start_date'].""); 
    $enddate = time();

    $time_passed = $enddate - $startdate;

    // if the first day after startdate is in "Week 1" according to your count
    $weekcount_1 = ceil ( $time_passed / (86400*7));

    // if the first day after startdate is in "Week 0" according to your count
    $weekcount_0 = floor ( $time_passed / (86400*7));

?>

答案 1 :(得分:0)

您可以直接从db中拖动周数和主日期。 例如,

"SELECT start_date, (WEEK(NOW()) - WEEK(start_date)) as desired_week as week from table";