Function to check next cron date


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');
  if($userDay >= 28 && $thisMonth == 2){
      $userDay = 28;
    if($thisMonth == 13){
      $thisMonth = 1;
  $return = strtotime($thisYear.'-'.$thisMonth.'-'.$userDay);
  return $return;
Last edited: