php从特定日期查找周数 [英] php find week number from specific date

查看:85
本文介绍了php从特定日期查找周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

我希望这是开始日期,所以现在是从这个日期开始的第3周。这是我迄今为止的代码,但仅显示ISO版本:

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;

我已经google了两个小时,但似乎找不到任何解决这个问题的事情!任何帮助将是非常感谢!

I have googled for past two hours but cannot seem to find any thing that resolves this! any help would be great thanks!

推荐答案

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

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

?>

这篇关于php从特定日期查找周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆