Fearpig Posted May 24, 2007 Share Posted May 24, 2007 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.) Quote Link to comment https://forums.phpfreaks.com/topic/52828-date-problem/ Share on other sites More sharing options...
marmite Posted May 24, 2007 Share Posted May 24, 2007 Hi, I'm not familiar with all the date functions but am replying to: a) bump your query, cos someone out there knows! b) the only thing that caught my eye is the number of different date formats you have - some d-m-y, some y-m-d, some m-d-y. Could that be it? Quote Link to comment https://forums.phpfreaks.com/topic/52828-date-problem/#findComment-260898 Share on other sites More sharing options...
Barand Posted May 24, 2007 Share Posted May 24, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52828-date-problem/#findComment-261011 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.