开发者

php find week number from specific date

I want to find a specific week number from the specific start date. For example $date is dragged from the database (i.e. 07/08/2011)

I want this to be the start date so it would be week 3 now from this date. This is the code i have so far but just shows the ISO version:

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

开发者_JAVA百科I have googled for past two hours but cannot seem to find any thing that resolves this! any help would be great thanks!


Get the difference between now and the startdate, and then divide by seven days (7*86400 seconds)

<?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));

?>


You can drag week number from db directly along with main date. For example,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜