Hello,
I was wondering if anyone has any experience creating a calendar in the weekly view (showing only the 7 days of the current week starting on monday). I know it can be done since I saw on the calendar section of this site, it has a weekly view available.
EDIT: I have made a simple php script here that works for this week. The only thing is that the "adder" function does not work . The adder function is so that you can progress from the current week to the next one. Also, I don't think my code is too efficient since I save two variables, day of the week and the month corresponding to it. Is it easy to convert that into one variable that I can call with the php date() function later?
Thanks a lot.
here are some lines I have so far (if they are of any help) and I'm just spitting out all the variables in echos to debug this:
$date = getDate();
if (!isset($add))
$add = 0;
$adder = $add * 7;
if ($adder>31)
$adder = floor($adder / 31);
echo "add is $add<br>";
echo "adder is $adder<br>";
$day = $date["mday"] + $adder;
$month = $date["mon"];
$monthnamer = getDate(mktime(0, 0, 0, $month, 1, $year));
$month_name = $monthnamer["month"];
$year = $date["year"];
$this_month = getDate(mktime(0, 0, 0, $month, 1, $year));
$next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year));
//Find out when this month starts and ends.
$first_week_day = $this_month["wday"];
$days_in_this_month = round(($next_month[0] - $this_month[0]) / (60 * 60 * 24));
if ($day>$days_in_this_month)
$day = $day - $days_in_this_month;
echo "day: $day<br>month: $month<br>monthnamer: $monthnamer<br>month_name: $month_name<br>year:$year<br>this_month: $this_month<br>next_month: $next_month<br>first_week_day: $first_week_day<br>days_in_this_month: $days_in_this_month<br>";
//do today minus first day
$diff_in_wks = floor(($day - $first_week_day) / 7);
$weeknum = $diff_in_wks;
if ($first_week_day>1) {
$weeknum = $weeknum + 1;
}
$sunday = $weeknum + (7 * $diff_in_wks) + 1;
$daynamer = getDate(mktime(0, 0, 0, $month, $day, $year));
$day_name = $daynamer["wday"];
if ($day_name==0) {
$sunday = $sunday - 1;
}
if ($sunday<1) {
$last_month = getDate(mktime(0, 0, 0, $month - 1, 1, $year));
$days_in_last_month = round(($this_month[0] - $last_month[0]) / (60 * 60 * 24));
$sunday = $days_in_last_month + $sunday + $first_week_day;
if ($weeknum==0) {
$sunday = $sunday - 1;
}
$used_last_month = "true";
}
//Monday Stuff
$monday = $sunday + 1;
if ((($used_last_month=="true") && ($monday>$days_in_last_month)) || ($monday>$days_in_this_month)) {
$monday = 1;
}
if (($day_name>1) && ($monday>$day)) {
$monday_month = $month - 1;
} else {
$monday_month = $month;
}
//Tuesday Stuff
$tuesday = $monday + 1;
if ((($used_last_month=="true") && ($tuesday>$days_in_last_month)) || ($tuesday>$days_in_this_month)) {
$tuesday = 1;
}
if ($tuesday>$monday) {
$tuesday_month = $monday_month;
} else {
$tuesday_month = $monday_month + 1;
}
//Wednesday Stuff
$wednesday = $tuesday + 1;
if ((($used_last_month=="true") && ($wednesday>$days_in_last_month)) || ($wednesday>$days_in_this_month)) {
$wednesday = 1;
}
if ($wednesday>$monday) {
$wednesday_month = $tuesday_month;
} else {
$wednesday_month = $tuesday_month + 1;
}
//Thursday Stuff
$thursday = $wednesday + 1;
if ((($used_last_month=="true") && ($thursday>$days_in_last_month)) || ($thursday>$days_in_this_month)) {
$thursday = 1;
}
if ($thursday>$wednesday) {
$thursday_month = $wednesday_month;
} else {
$thursday_month = $wednesday_month + 1;
}
//Friday Stuff
$friday = $thursday + 1;
if ((($used_last_month=="true") && ($friday>$days_in_last_month)) || ($friday>$days_in_this_month)) {
$friday = 1;
}
if ($friday>$thursday) {
$friday_month = $thursday_month;
} else {
$friday_month = $thursday_month + 1;
}
//Saturday Stuff
$saturday = $friday + 1;
if ((($used_last_month=="true") && ($saturday>$days_in_last_month)) || ($saturday>$days_in_this_month)) {
$saturday = 1;
}
if ($saturday>$friday) {
$saturday_month = $friday_month;
} else {
$saturday_month = $friday_month + 1;
}
//Sunday Stuff
$sunday = $saturday + 1;
if ((($used_last_month=="true") && ($sunday>$days_in_last_month)) || ($sunday>$days_in_this_month)) {
$sunday = 1;
}
if ($sunday>$saturday) {
$sunday_month = $saturday_month;
} else {
$sunday_month = $saturday_month + 1;
}
//END WEEKS
echo "weeknum: $weeknum<br>sunday: $sunday<br>diff_in_wks: $diff_in_wks<br>";
Echo "<br>Output it all:<br>Monday: $monday_month/$monday<br>Tuesday: $tuesday_month/$tuesday<br>Wednesday: $wednesday_month/$wednesday<br>Thursday: $thursday_month/$thursday<br>Friday: $friday_month/$friday<br>Saturday: $saturday_month/$saturday<br>Sunday: $sunday_month/$sunday<br>";