Jump to content

Recommended Posts

Hi guys,

Can someone have a look at my code and see where I've gone wrong!  :(

 

The code below populates a calendar with a list of events for each day. Unfortunately the list of events appears under the correct day and year but repeat themselves for every month (i.e. an event on the 18th May also appears under 18th June, 18th July, 18th August... and so on. )

 

 

Each event has a start date and a duration (in days) so I convert the startdate into an integer of seconds, then add on the duration in seconds to find the enddate. I then list all events where the startdate <= calendar date and enddate >= calendar date.

 

 

<?php 

$Calendar_Date = date("d/m/Y",mktime(0,0,0,$Month,$Day,$Year));

echo "$Calendar_Date<br>";

$sql_Event_Details="SELECT * FROM tbl_Visit";
$Event_Details=odbc_exec($conn,$sql_Event_Details);
if (!$Event_Details)
{exit("Error in SQL");}
  

while (odbc_fetch_row($Event_Details)) 
{	

$Event_Title=odbc_result($Event_Details,"Event_Title");
$Duration=odbc_result($Event_Details,"Duration");
$Duration_Seconds=86400 * $Duration;
$Start_Date=odbc_result($Event_Details,"Event_Date");		
$Start_Date_Seconds= strtotime($Start_Date);
$End_Date_Seconds=$Start_Date_Seconds + $Duration_Seconds;
$End_Date=($Start_Date !='')?date("Y-m-d",$End_Date_Seconds):'';

$Format_Start_Date = ($Start_Date !='')?date("d/m/Y",strtotime($Start_Date)):'';
$Format_End_Date = ($End_Date !='')?date("d/m/Y",strtotime($End_Date)):'';

if (($Format_Start_Date <= $Calendar_Date) AND ($Format_End_Date >= $Calendar_Date)){

	echo "<span class='Body3'>$Event_Title</span><br>";

}else{
	echo "";
}	


}
?>

 

If anyone can help I'd really appreciate it as this is just about my final stumbling block for this project and its driving me mad! (I've probably just stared at it for too long.)

Link to comment
https://forums.phpfreaks.com/topic/52828-date-problem/
Share on other sites

You might find it easier to work in with unix times until you actually need to format for display.

Use strtotime for easy calculations.

 

<?php
$start = strtotime('2007-05-24')
$duration = 3;

$add = $duration-1;
$end = strtotime ("+$add days", $start);
?>

Link to comment
https://forums.phpfreaks.com/topic/52828-date-problem/#findComment-261011
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.