dadamssg87 Posted June 3, 2011 Share Posted June 3, 2011 I'm trying to convert from making potentially 31 queries to pull events to display in each day in a calendar to making one query to pull all the events for that month and putting those events in a multidimensional array to display in the calendar. I'm having trouble figuring out the best way to check if the current day the script is on has events. The events have a start timestamp and an end timestamp and i know i need to compare these values to the start (2011-06-02 00:00:00) and end (2011-06-02 23:59:59) timestamps of the day the script is on. <?php $month_number = 6; $year = 2011; $day_number = 30; //cycle through all the days of the month for($day = 1; $day <= $day_number; $day++) { $start_current_date = mktime(0,0,0, $month_number, $day, $year); //get the very beginning of the day $end_current_date = mktime(23,59,59, $month_number, $day, $year); //get the very end of the day //cycle through events/bookings foreach($bookings as $key => $value) { $startstamp = strtotime($bookings[$key]['start']); $endstamp = strtotime($bookings[$key]['end']); // part i need help with, most efficient way to determine if script should display events // based on $startstamp , $endstamp, $start_current_date, and $end_current_date. } } ?> any advice would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/238275-php-to-query-dates/ Share on other sites More sharing options...
dadamssg87 Posted June 3, 2011 Author Share Posted June 3, 2011 fiddled with and figured it out. <?php $month_number = 6; $year = 2011; $day_number = 30; //cycle through all the days of the month for($day = 1; $day <= $day_number; $day++) { $start_current_date = mktime(0,0,0, $month_number, $day, $year); //get the very beginning of the day $end_current_date = mktime(23,59,59, $month_number, $day, $year); //get the very end of the day //cycle through events/bookings foreach($bookings as $key => $value) { $startstamp = strtotime($bookings[$key]['start']); $endstamp = strtotime($bookings[$key]['end']); if($startstamp <= $current_date && $endstamp >= $current_date || $startstamp >= $current_date && $endstamp <= $end_current_date) { echo $bookings[$key]['name']; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/238275-php-to-query-dates/#findComment-1224478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.