douba4933 2017-01-08 07:54
浏览 84
已采纳

使用MYSQL和PHP将星期几转换为当月的日期

Spent a while searching and couldn't find any answers. Really simple question I hope.

In my database I have a string column dayOfWeek.

I use this to track what day of week weekly events are scheduled for. Usually I match the dayOfWeek to the current day using PHP and display the correct events.

What I want to do is show a calendar into the future which makes a list of the future dates of the weekly recurring event.

For example, if the event takes place on Tuesday, and Feb 2017 has Tuesdays on the 7th, 14th, 21st, and 28th. I'd like to use PHP to display as such.

I know strtotime() is used to do the opposite, find a day from the date, but can the opposite be done easily?

Sorry if my question is poorly worded or missing information.

  • 写回答

3条回答 默认 最新

  • dongweicha6077 2017-01-08 08:23
    关注

    USE CASE FOR FEB 2017 TUESDAYS

    $n=date('t',strtotime("2017-02-01")); // find no of days in this month
    $dates=array();
    for ($i=1;$i<=$n;$i++){
         $day=date("D",strtotime("2017-02-".$i)); //find weekdays
    
        if($day=="Tue"){
            $dates[]="2017-02-".$i;
        }
    }
    print_r($dates);
    

    http://phpfiddle.org/main/code/s8wq-xx44

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器