giba Posted February 3, 2009 Share Posted February 3, 2009 Hi There, I am working on a calendar, and I am with a problem. How could I know if the day is a sunday? Because I need to perform a sum of extra tax based on the weekday, and if it is Sunday it's applied extra tax. But for solving this post, print it as bold face is OK for me, because I have the Math already done, just need to get the sunday. Thanks in advance! Take a look at my working calendar <?php $monthNames = Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if ( !isset( $_REQUEST["month"] ) ) { $_REQUEST["month"] = date("n" ); } if ( !isset( $_REQUEST["year"] ) ) { $_REQUEST["year"] = date("Y" ); } $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ( $prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ( $next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <div class="container" > <div id="calendar_div" > <table> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Anterior</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Próximo</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> </tr> <tr><td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td></tr> <?php $timestamp = mktime( 0, 0, 0, $cMonth, 1, $cYear ); $maxday = date( "t", $timestamp ); $thismonth = getdate( $timestamp ); $startday = $thismonth['wday']; for( $i=0; $i < ( $maxday+$startday ); $i++ ) { if( ( $i % 7 ) == 0 ) { echo "<tr>\n"; } if( $i < $startday ) { echo "<td></td>\n";} else { echo "<td align='center' valign='middle' height='20px;'>". ( $i - $startday + 1 ) . "</td>\n"; } if( ( $i % 7 ) == 6 ) { echo "</tr>\n"; } } ?> </table> </td> </tr></table> </div> Quote Link to comment Share on other sites More sharing options...
Snart Posted February 3, 2009 Share Posted February 3, 2009 I've only glanced at your script, but couldn't you just go date("l", $timestamp); //Lowercase L or date("D", $timestamp); ? Quote Link to comment Share on other sites More sharing options...
giba Posted February 3, 2009 Author Share Posted February 3, 2009 Yes, I know it, but I would like to know how to make the calendar do some action if the day is a Sunday, like to make it in bold. How do I implement it, because I have a number for the days and what is exactly the relation between the days and the date('l',$timestamp). What can I get a visual sign of the Sundays? Quote Link to comment Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 getdate Would that work out for you? Quote Link to comment Share on other sites More sharing options...
giba Posted March 14, 2009 Author Share Posted March 14, 2009 Well, I've found that the line: ( $i % 7 ) does the trick for Sundays. So now, I can style the Sunday based on this operation. Quote Link to comment Share on other sites More sharing options...
fook3d Posted March 14, 2009 Share Posted March 14, 2009 date() will give you more information about date(). date('l', $timestamp); will return Sunday if the date you are viewing it is a sunday. So surely a simple if statement will make it bold? <?php $day = date('l', $timestamp); if($day == 'Sunday') echo '<b>' . $day . '</b>'; else echo $day; ?> Or am I missing something? Quote Link to comment Share on other sites More sharing options...
samshel Posted March 14, 2009 Share Posted March 14, 2009 or you can try... <?php $timestamp = mktime( 0, 0, 0, $cMonth, 1, $cYear ); $maxday = date( "t", $timestamp ); $thismonth = getdate( $timestamp ); $startday = $thismonth['wday']; for( $i=0; $i < ( $maxday+$startday ); $i++ ) { if( ( $i % 7 ) == 0 ) { echo "<tr>\n"; } if( $i < $startday ) { echo "<td></td>\n";} else { if(date("N", strtotime($cYear."-".$thismonth."-".($i - $startday + 1))) == 7) { echo ($cYear."-".$thismonth."-".($i - $startday + 1)). " is Sunday !! Hurray !!"; } else { echo ($cYear."-".$thismonth."-".($i - $startday + 1)). " is a WeekDay and my boss just called !!"; } echo "<td align='center' valign='middle' height='20px;'>". ( $i - $startday + 1 ) . "</td>\n"; } if( ( $i % 7 ) == 6 ) { echo "</tr>\n"; } } ?> Quote Link to comment 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.