dongyan3237 2018-07-31 09:00
浏览 149

如何确定cron执行日期直到某个日期?

I want to determine the dates with the hours when Crons (of a Crontab) are going to run.

Is there a solution to recover all the dates of execution of a cron? For example, the variable crontab is "15 7 * * *" and the end date is "2018-08-05", i would like to find these dates :

  • 2018-08-01 07:15:00 UTC
  • 2018-08-02 07:15:00 UTC
  • 2018-08-03 07:15:00 UTC
  • 2018-08-04 07:15:00 UTC
  • 2018-08-05 07:15:00 UTC

All my scripts are in PHP. If there is a solution in php it would be better.. Or an API ? Thanks for purpose...

  • 写回答

2条回答 默认 最新

  • duanjia9577 2018-07-31 09:39
    关注

    If you just need to count and see all the dates from "now" to "limit date", you can use this code:

    $date = new DateTime("now");
    $endDate = new DateTime("2018-08-05 07:15:00");
    $count = 0;
    
    while ($date <= $endDate ) {
        $count++;
        $date->modify("+1day");
        echo $date->format("Y-m-d 07:15:00"), "
    ";
    }
    echo "There is $count dates";
    

    But if you need just start cron in need time - use two cron records:

    15 7 * 1-7 * user   command #start year to July
    15 7 1-5 8 * user   command #August 1 - 5
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口