doukao2180 2017-01-26 15:37
浏览 59
已采纳

PHP - 日期和时间显示问题

I hope that you may have a hint for me, how I can solve this issue. I am showing to my customers some kind of a ranking list. The data within the ranking list are really important and the ranking list counts all selected points from tuesday for 2 weeks until monday last week. Everything is working so far, except when today is tuesday, because with my function, the program shows on tuesday the ranking list for the last two weeks except from last week.

Here is my code I am using:

$start_date_week=strtotime('-2 week tuesday 00:00:00');
$end_date_week=strtotime('-1 week monday 23:59:59');

So if today is tuesday, my program shows me the data from the last 2 weeks. On every other day it shows the data from last week correct. Any idea how I can make this work, even if today is tuesday?

With those 2 variables I am getting my data from the database and those two variabes also show the date from until the date to:

.date("d.m.Y", $start_date_week)." - ".date("d.m.Y", $end_date_week)."

Please let me know how I can solve this issue.

Thanks, Chris

  • 写回答

1条回答 默认 最新

  • dongweng9474 2017-01-26 16:03
    关注

    I'll add this here as I feel you're over thinking something that could be simplified:

    $timestamp = time();
    if (date('D', $timestamp) === 'Tue')
    {
        // run a database query for 2 weeks of logs
        echo "2 week log";
    } else {
        // run database query for 1 week of logs
        echo "1 week log";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题