Mundo Posted March 22, 2009 Share Posted March 22, 2009 <? mysql_connect("localhost","root",""); mysql_select_db("clicker"); include "tpl/header.tpl"; include "tpl/navigation_calendar.tpl"; $month1 = mktime(0, 0, 0, date("m"), date("d"), date("y")); $month2 = mktime(0, 0, 0, date("m")+1, date("d"), date("y")); $month3 = mktime(0, 0, 0, date("m")+2, date("d"), date("y")); $month4 = mktime(0, 0, 0, date("m")+3, date("d"), date("y")); $month5 = mktime(0, 0, 0, date("m")+4, date("d"), date("y")); $month6 = mktime(0, 0, 0, date("m")+5, date("d"), date("y")); $month7 = mktime(0, 0, 0, date("m")+6, date("d"), date("y")); $month8 = mktime(0, 0, 0, date("m")+7, date("d"), date("y")); $month9 = mktime(0, 0, 0, date("m")+8, date("d"), date("y")); $month10 = mktime(0, 0, 0, date("m")+9, date("d"), date("y")); $month11 = mktime(0, 0, 0, date("m")+10, date("d"), date("y")); $month12 = mktime(0, 0, 0, date("m")+11, date("d"), date("y")); include "tpl/calendar_info.tpl"; $date = time(); $day = date("d", $date); $month = date("m", $date); $year = date("y", $date); $first_day = mktime(0, 0, 0, $month, 1, $year); $day_of_week = date('D', $first_day) ; $title = date('F', $first_day); switch($day_of_week){ case "Mon": $blank = 0; break; case "Tue": $blank = 1; break; case "Wed": $blank = 2; break; case "Thu": $blank = 3; break; case "Fri": $blank = 4; break; case "Sat": $blank = 5; break; case "Sun": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); echo "<table border=\"1\">"; echo "<tr><td colspan=\"7\"><h1 align=\"right\">$title $year</h1></td></tr>"; echo "<tr><td width=\"42\"><b>Mon</b></td><td width=\"42\"><b>Tues</b></td><td width=\"42\"><b>Weds</b></td><td width=\"42\"><b>Thurs</b></td><td width=\"42\"><b>Fri</b></td><td width=\"42\"><b>Sat</b></td><td width=\"42\"><b>Sun</b></td></tr>"; $day_count = 1; echo "<tr>"; while ($blank > 0) { echo "<td bgcolor=\"#FFFFFF\"> </td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month) { echo "<td> $day_num </td>"; $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } while ($day_count >1 && $day_count <=7) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; include "tpl/sidebar.tpl"; include "tpl/footer.tpl"; ?> I've got this which will generate this months calendar, there is also a form which allows me to select another month in the next 12 (http://i39.tinypic.com/14afp1j.jpg). How would I go about incorporating this so it will generate the calendar for a selected month? The date selected from the form is $_GET['date'] (which would return "2009-03" for example). Could I just use something like: if($_GET['date']) { $date = time() + something? } else { $date = time(); } If so, what would "something" be? Link to comment https://forums.phpfreaks.com/topic/150620-timedate/ Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 First of all, what are you trying to do? There's probably a much easier way. There is a build in PHP calendar, why not use that? http://us3.php.net/manual/en/ref.calendar.php Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791178 Share on other sites More sharing options...
Mundo Posted March 22, 2009 Author Share Posted March 22, 2009 I just want to change which month is generated from my form. The screenshot should illustrate. I think I just need to change the "time()" but I don't understand how to do that. Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791183 Share on other sites More sharing options...
Mundo Posted March 22, 2009 Author Share Posted March 22, 2009 [code=php:0]if($_GET['date']) { $date = time() + $_GET['date']; } else { $date = time(); } So at the minute, time() + $_GET['date'] doesn't give the right result. How do I add 1 month to time() ? Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791189 Share on other sites More sharing options...
Mundo Posted March 22, 2009 Author Share Posted March 22, 2009 if($_GET['date']) { $formmonth = date("m", strtotime($_GET['date'])); $formyear = date ("y", strtotime($_GET['date'])); $days_thatmonth = cal_days_in_month(0, $formmonth, $formyear); $date = time() + ($days_thatmonth * 24 * 60 * 60); // days in chosen month * 24hrs * 60 mins * 60 secs echo $date; } else { $date = time(); } Why doesn't that work? Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791206 Share on other sites More sharing options...
Mundo Posted March 22, 2009 Author Share Posted March 22, 2009 I know it's something to do with the following line: $date = time() + ($days_thatmonth * 24 * 60 * 60); Any ideas on the maths?! Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791213 Share on other sites More sharing options...
Mundo Posted March 22, 2009 Author Share Posted March 22, 2009 Ah I know why, if I select June, it will only add the amount of seconds in June and not all the seconds between now and the end of June... Anybody have any ideas on how I can calculate this? Nobody seems to be responding... Link to comment https://forums.phpfreaks.com/topic/150620-timedate/#findComment-791232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.