Jump to content

better way to finding all years


joe_g
 Share

Recommended Posts

Hi,

is there a faster/better way to do this?

With events containing startdate (mandatory) and enddate (optional) - I'm looking up what years has one or more events:

The result is a list of years that contains events. It works fine, but it's a bit slow.

<?for($i=2014;$i>=1980;$i--) {
   $date_start = new DateTime();
   $date_end = new DateTime();
   $date_start = $date_start->setDate($i, 1, 1);
   $date_end = $date_end->setDate($i+1, 1, 1);
   $date_start_ts = $date_start->getTimestamp();
   $date_end_ts = $date_end->getTimestamp();
   $e = $pages->get('/event')->numChildren("enddate!='',enddate>$date_start_ts,startdate<=$date_end_ts");
   $e2 = $pages->get('/event')->numChildren("enddate='',startdate>$date_start_ts,startdate<=$date_end_ts");
   $tot = $e+$e2;

   if($tot>0) {
      echo $i; //print year since it has events
   }
}
?>

tx, j

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...