dongqiao9015 2019-08-19 19:56
浏览 46

在下一个工作日发生时修改日期时间对象并保留原始日期的小时和分钟

I need to go to the next appointment which happens at the same time every day that's being modified, but when I modify it by the next interval day, it wipes the hours and minutes to 00:00

I've tried everything I can think of

foreach($recurring_appt as $ra)
{   //check for recurring appts next occurance
    $check_rec_stop_date = new DateTime($ra->stop_recurring);
    if($check_rec_stop_date >= $end_date){
        $i=0;
        if($ra->start_date <= $start_date->format('Y-m-d H:i:s')){
            $t = new DateTime($ra->start_date);
            $mod = 'next '.$days[$i][0];
            $check_rec = clone $t->modify($mod);
            echo $check_rec->format('m-d');
            if($check_rec->format('m-d') == $start_date->format('m-d')){
                array_push($rec_start_block,(new DateTime($ra->start_date))->modify($mod));
                array_push($rec_end_block, (new DateTime($ra->end_date))->modify($mod));
            }
        }
        // elseif()        
    }

    $i++;                
}

as I said - this modifies the date correctly to the next occurance of that appointment, but i resets the clock to 0:00 when I need it to keep that information, just modify the day (and month if applicable)

  • 写回答

1条回答 默认 最新

  • dongliyan7318 2019-08-19 22:58
    关注

    I think I will try the DateTimeImmutable when cleaning up my code to make it more efficient, but the only way around my original problem was to append the hours and minutes onto the modified date object after it has been modified:

     $mod = 'next '.$days[$i][$j];
                        $check_rec = clone $t->modify($mod);
                        echo $check_rec->format('m-d')."
    ";
                        if($check_rec->format('m-d') == $start_date->format('m-d')){
                            array_push($rec_start_block, ((new DateTime($ra->start_date))->modify($mod)->setTime($hour, $mins)));
                            array_push($rec_end_block, ((new DateTime($ra->end_date))->modify($mod)->setTime($chour, $cmins)));
                            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应