Jump to content

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/238275-php-to-query-dates/
Share on other sites

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'];
                }         

}
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/238275-php-to-query-dates/#findComment-1224478
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.