Jump to content

Problem with a calendar


jiveturkey420

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

[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 ;)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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