doulang6695 2011-01-12 22:41 采纳率: 100%
浏览 46
已采纳

使用PHP DateInterval创建重复事件

So I have spent quite a bit of time researching how best to add recurring events to my calendar application.

I would like to use the PHP DateInterval function and have formulated the code below to try and work out how to create a recurring event based on the original events Start Date, Finish Date and the EndDate of Recurrence.

//user defined event start and finish dates
$eventStart = new DateTime( '2011-01-31 09:00:00' );
$eventFinish = new DateTime( '2011-01-32 17:00:00' );

//user defined event recurring end date
$endRecurring = new DateTime( '2011-05-31 23:59:59' );

//define for recurring period function
$begin = $eventStart;
$end = $endRecurring;

//define our interval
$interval = DateInterval::createFromDateString('next friday');
$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE);

//loop through and create new dates for recurring events
foreach ( $period as $dt )
  $recurringStartDate = $dt->format( "l Y-m-d H:i:s
" );
  $recurringEndDate = ?NOT SURE HOW TO PROCESS THE END DATE IN THIS START DATE FOREACH LOOP?

This should hopefully create a list of new event start dates. BUT I also need to define new end dates for my recurring events. How do I do this? Do I need to process this in the event start date foreach loop?

My other question is how I could combine multiple dateIntervals to take care of Repeat every Monday, Wednesday and Friday? Currently only single dateIntervals are working like next friday

  • 写回答

4条回答 默认 最新

  • douyinglan2599 2013-04-25 19:46
    关注

    There is a Date/Calendar recursion library for PHP 5.2+ by Thomas Planer. Its not DateInterval, but it seems to do the trick. Check it out at https://github.com/tplaner/When.

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

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码