Jump to content

Time/Date


Mundo

Recommended Posts

<?
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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.