jiveturkey420 Posted July 18, 2012 Share Posted July 18, 2012 I am relatively new to PHP. I create a simple calendar script, but I've discovered an error. It was 10:52pm EST(UTC -5) on Thursday, Jul 17 2012 realtime, but my program was saying it was Jul 18 2012. I figure it's something with the date() that I'm not doing right, but I'm not sure. Perhaps someone can help me out? I'll post the script below.... <?php /* Calendar Begin */ $current_day_name = date(l); $current_day_short_name = date(D); $current_day_num = date(d); $current_day_suffix = date(S); $current_month_name = date(F); $current_month_num = date(n); $current_year = date(Y); $current_month_total_days = cal_days_in_month(CAL_GREGORIAN,$current_month_num,$current_year); $current_month_first_day = mktime(0,0,0,$current_month_num,1,$current_year); $current_month_first_day_name = date('D',$current_month_first_day); $days_in_week = 1; $days_in_month = 1; switch ($current_month_first_day_name) { case "Sun": $empty_cell = 0; break; case "Mon": $empty_cell = 1; break; case "Tue": $empty_cell = 2; break; case "Wed": $empty_cell = 3; break; case "Thu": $empty_cell = 4; break; case "Fri": $empty_cell = 5; break; case "Sat": $empty_cell = 6; break; } echo "<font size='5'><i>".$current_month_name." - ".$current_year."</i></font>"; echo "<table border='1'>"; echo "<tr> <th width='70' height='30'>Sun</th> <th width='70'>Mon</th> <th width='70'>Tue</th> <th width='70'>Wed</th> <th width='70'>Thu</th> <th width='70'>Fri</th> <th width='70'>Sat</th></tr>"; echo "<tr>"; while ($empty_cell > 0) { echo "<td height='50'><p align='center'> --- </p></td>"; $days_in_week++; $empty_cell--; } while ($days_in_month <= $current_month_total_days) { echo "<td height='50'><p align='center'>".$days_in_month."</p></td>"; $days_in_month++; $days_in_week++; if($days_in_month == $current_day_num) { echo "<td height='50'><p align='center'><font color='red'><b>".$days_in_month."</b></font></p></td>"; $days_in_month++; $days_in_week++; } if ($days_in_week > 7) { echo "<tr></tr>"; $days_in_week = 1; } } echo "</tr></table>"; /* Calendar End */ echo $current_day_name; ?> If anyone can be any help, it'd be greatly appreciated. jiveTurkey420 Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/ Share on other sites More sharing options...
Barand Posted July 18, 2012 Share Posted July 18, 2012 is the date.timezone setting correct in your php.ini file? date.timezone = America/New_York Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362341 Share on other sites More sharing options...
jiveturkey420 Posted July 18, 2012 Author Share Posted July 18, 2012 I looked for php.ini by running "whereis php.ini" in my terminal, but it gave me 7 or 8 different locations. Here is the output. [jon@localhost ~]$ whereis php.ini php: /bin/php /usr/bin/php /etc/php.ini /etc/php.d /lib/php /usr/lib/php /usr/share/php /usr/share/man/man1/php.1.gz I am running Fedora 17 Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362434 Share on other sites More sharing options...
Barand Posted July 18, 2012 Share Posted July 18, 2012 run <?php phpinfo(); ?> That will tell you which is being used Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362465 Share on other sites More sharing options...
jiveturkey420 Posted July 18, 2012 Author Share Posted July 18, 2012 Alright, I got that. I run "chown jon /etc/php.ini" , and then open it in gedit. When I go to save it, it says that's it's unable to make a backup, and it won't save. Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362468 Share on other sites More sharing options...
Mahngiel Posted July 18, 2012 Share Posted July 18, 2012 because you only modified rights to the file,and not the directory, so the backup file failed.. you'll need at least chmod the folder. Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362472 Share on other sites More sharing options...
jiveturkey420 Posted July 18, 2012 Author Share Posted July 18, 2012 Yeah Mahngiel, that was it, thank you. I don't see where in php.ini timezones can be modified. Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362478 Share on other sites More sharing options...
xyph Posted July 18, 2012 Share Posted July 18, 2012 [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = UTC ; http://php.net/date.default-latitude ;date.default_latitude = 31.7667 ; http://php.net/date.default-longitude ;date.default_longitude = 35.2333 ; http://php.net/date.sunrise-zenith ;date.sunrise_zenith = 90.583333 ; http://php.net/date.sunset-zenith ;date.sunset_zenith = 90.583333 Alternately, set it during runtime date_default_timezone_set BTW - You've got to SASS it Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362479 Share on other sites More sharing options...
jiveturkey420 Posted July 18, 2012 Author Share Posted July 18, 2012 So you're saying that I have to remove the semicolon before "date.timezone" and add a " = UTC" at the end? I found this bit that you posted in php.ini, and it's actually the same as mine. Only there was a semicolon before date.timezone, and no = UTC Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362521 Share on other sites More sharing options...
Mahngiel Posted July 18, 2012 Share Posted July 18, 2012 the semicolon before a line in a php.ini comments a line out... meaning the properties will not be read. Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362526 Share on other sites More sharing options...
xyph Posted July 18, 2012 Share Posted July 18, 2012 Assuming you can't find date.timezone anywhere else in your php.ini, then yes! Remove the semi-colon, and add = yourtimezoneofchoice afterwards. http://php.net/manual/en/timezones.php It might be a good idea to just set it in the script/runtime... in the event that you are using it on a server that doesn't have access to php.ini. If this isn't the case, by all means stick to the setting in php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/265872-problem-with-a-calendar/#findComment-1362527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.