php查找特定日期的周数

发布于 2024-12-01 17:19:49 字数 300 浏览 0 评论 0原文

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

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

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

我已经用谷歌搜索了过去两个小时,但似乎找不到任何可以解决这个问题的东西!任何帮助将非常感谢!

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;

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事风中埋 2024-12-08 17:19:49

获取现在与开始日期之间的差值,然后除以 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));

?>

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

?>
浪菊怪哟 2024-12-08 17:19:49

您可以直接从数据库中将周数与主要日期一起拖动。
例如,

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

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文