Jump to content

jack13580

Members
  • Posts

    3
  • Joined

  • Last visited

jack13580's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, took me so long to figure out how to do this the first time and it didn't even work but with yours especially being so short just makes me sad but it does work I just had to change $dp to while($d1 < $d2) { $dp[] = $d1->format('Y-m-d'); $d1->modify('+1 day'); } because my free web host only has php 5.2.17
  2. Sorry about my horrible description, here's a revised one I am making my own custom calendar application/script and have just finished with one of its functions This function is to calculate the days of the month before the current month according to what day the current month started on and display them accordingly I was able to get it working, but it doesn't display the correct numbers all the time; some times it does and some times it doesn't you can view my calendar at http://troop557.vacau.com/calendar.php this can be vied by going to march and see that the last month is supposedly 31 days long but go to that month, February and its only 28 days long the code I came up with to get this to work is below, anyone know why its doing this? $numDays = date("t", $currentTimeStamp); $counter = 0; for($i = 1; $i < $numDays+1; $i++, $counter++){ $monthstring = $month; $monthlength = strlen($monthstring); $daystring = $i; $daylength = strlen($daystring); $timeStamp = strtotime("$year-$month-$i"); $timeStamp_before = strtotime("$year-$month_before-$i"); $month_before = ($month == 1) ? "12" : $month-1; $year_before = ($month == 1) ? $year-1 : $year; $firstDay = date("w", $timeStamp); $days_before = date("j", $timeStamp_before); $days_before_thisMonth = $days_before - $firstDay; $days_before_thisMonth = $days_before_thisMonth+1; for($if1=0;$if1!=1 && $i < 2;$if1++){ $if_goes_over_check = ($days_before - $days_before_thisMonth) + 1; } if($i == 1) { //$firstDay = ($firstDay > 4) ? $firstDay = 4 : $firstDay; for($fd = 0; $fd < $firstDay; $fd++, $counter++, $days_before_thisMonth++) { echo "<td>"; echo "<a href=\"?day=".$days_before_thisMonth."&month=".$month_before."&year=".$year_before."\" class=\"calendar-link\""; echo ">".$days_before_thisMonth."</a><br />"; } echo "</td>\r\n"; } } About the link to the calendar on my website, sorry that you feel that I'm a scumbag virus spreader but I would rather not want to have the risk of going to jail and would rather get better at building and designing websites and I really need help with this
  3. I am making my own custom calendar application/script and have just finished with one of its functions This function is to calculate the days of the month before the current month according to what day the current month started on and display them accordingly The logic I used to get this to work which took me a week to figure this out works most of the time, my questions are: 1. Is there a better way of doing this? 2. Is there anything I may have overlooked? 3. What may be the cause for the incorrect numbers shown for example go back 2 months to see how off it is $numDays = date("t", $currentTimeStamp); $counter = 0; for($i = 1; $i < $numDays+1; $i++, $counter++){ $monthstring = $month; $monthlength = strlen($monthstring); $daystring = $i; $daylength = strlen($daystring); $timeStamp = strtotime("$year-$month-$i"); $timeStamp_before = strtotime("$year-$month_before-$i"); $month_before = ($month == 1) ? "12" : $month-1; $year_before = ($month == 1) ? $year-1 : $year; $firstDay = date("w", $timeStamp); $days_before = date("j", $timeStamp_before); $days_before_thisMonth = $days_before - $firstDay; $days_before_thisMonth = $days_before_thisMonth+1; for($if1=0;$if1!=1 && $i < 2;$if1++){ $if_goes_over_check = ($days_before - $days_before_thisMonth) + 1; } if($i == 1) { //$firstDay = ($firstDay > 4) ? $firstDay = 4 : $firstDay; for($fd = 0; $fd < $firstDay; $fd++, $counter++, $days_before_thisMonth++) { echo "<td>"; echo "<a href=\"?day=".$days_before_thisMonth."&month=".$month_before."&year=".$year_before."\" class=\"calendar-link\""; echo ">".$days_before_thisMonth."</a><br />"; } echo "</td>\r\n"; } } you can view this working here: http://troop557.vacau.com/calendar.php
×
×
  • 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.