Forum Moderators: coopster

Message Too Old, No Replies

Calendar Challenge

         

ta_da

11:58 am on Feb 23, 2007 (gmt 0)

10+ Year Member



Hi everyone,

I have built a little calendar based on Jason Gilmore's ARTICLE [zend.com]. on Zend. I am a pretty decent php programmer for day to day stuff, but I have to admit that this is my first date processing task of any size so I need some guidance if possible to get me up to speed.

The problem :
Jason's calendar runs off a DB which stores a single event in a date field and renders each day cell based on these values like this...


if (in_array($currentDay,$dateArray)) {

$date = "$year-$month-$currentDay";

$calendar .= "<td class='linkedday'>
<a href='blogs.php?date=$date'
class='calendarlink'>$currentDay</a></td>";
...
...

Example output...

[zend.com...]

My need :

I would like to alter it so that I can render a SEQUENCE of successive dates in the called based on TWO fields in the database, a 'start' date and an 'end' date. Basically I want to build the basis of a project scheduler, and its not ideal/practical to have to input every day as a seperate event. I just want to pick two dates and let the calendar render all cells as such.

Is there a dateWithinRange() function either inbuilt or suggested by a coder which I could use to achieve what I want?

i.e..... (CRAP PSEUDO CODE IDEA)


if (dateWithinRange($currentDay,$startdate, $enddate)) {

$date = "$year-$month-$currentDay";

$calendar .= "<td class='linkedday'>
<a href='blogs.php?date=$date'
class='calendarlink'>$currentDay</a></td>";
...
...

I am probably overlooking something dead easy but help would be greatly appreciated nonethess :)

Cheers

sned

5:14 pm on Feb 23, 2007 (gmt 0)

10+ Year Member



You could convert the start and end dates to unix timestamps, then as the calendar is being rendered, check each day's timestamp:

if($currentDaystamp > $startDaystamp && $currentDaystamp < $endDaystamp){
// do something with this particular cell in the table
}

- sned