1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Function to check next cron date

Discussion in 'General PHP and MySQL Discussions' started by nrep, Oct 12, 2013.

  1. nrep

    nrep Well-Known Member

    I'm coding something (not in the XF core) where I need to know the next available date that meets some cron-like criteria. For example, I will have a day (0-31), month (0-12) and year (0+) - where 0 acts as a wildcard.

    I need to find the next date that meets those conditions. For example, if I had day=10, month=6, year=0 - it would give me the value 10-06-2014 (as of today).

    I found a function that does some of this, but only using the day (ignoring month/year), however I can't figure out how to extend it. Has anyone does this before, or can see how I can modify it?

    function OLDnextDate($userDay){    
    $today date('d'); // today
    $target date('Y-m-'.$userDay);  // target day
    if($today <= $userDay){
    $return strtotime($target);
    $thisMonth date('m') + 1;
    $thisYear date('Y');
    $userDay >= 28 && $thisMonth == 2){
    $userDay 28;
    $thisMonth == 13){
    $thisMonth 1;
    $return strtotime($thisYear.'-'.$thisMonth.'-'.$userDay);
    Last edited: Oct 13, 2013

Share This Page