TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-02-2008, 07:45 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application Coloring today and week-end in a calendar...

Good day to you all,
I'm working on a calendar script.
I'm facing 2 questions;

1. How, if is this month, can I have the day in a different color ?
2. how could I have the Saturday and Sunday show in different color ?


Here is my code:
PHP Code:

<?
function showMonth($month$year)
{
    
$date mktime(1200$month1$year);
    
$daysInMonth date("t"$date);
    
// calculate the position of the first day in the calendar (sunday = 1st column, etc)
    
$offset date("w"$date);
    
$rows 1;

    echo 
"<table border=\"1\" align=\"center\">\n";
    echo 
"<tr><td colspan=\"7\"><h1>" date("F Y"$date) . "</h1></td></tr>";
    echo 
"<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>";
    echo 
"\n\t<tr>";
    for(
$i 1$i <= $offset$i++)
    {
        echo 
"<td></td>";
    }
    for(
$day 1$day <= $daysInMonth$day++)
    {
        if( (
$day $offset 1) % == && $day != 1)
        {
            echo 
"</tr>\n\t<tr>";
            
$rows++;
        }

      echo 
"<td  valign=\"top\"><table border=\"0\" align=\"center\">";
      echo 
"<tr><td width=\"100\" valign=\"top\" bgcolor=\"cccc99\">" $day "</td></tr>";
      echo 
"<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
      echo 
"</table></td>";

    }
    while( (
$day $offset) <= $rows 7)
    {
        echo 
"<td></td>";
        
$day++;
    }
    echo 
"</tr>\n";
    echo 
"</table>\n";
}
showmonth(122008);
?>
Thanks !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 12-02-2008, 08:34 AM   #2 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Default

I foud it thanks you !
PHP Code:

if ($month == date("m") && $day == date("d")){
      echo 
"<td  valign=\"top\"><table border=\"0\" align=\"center\">";
      echo 
"<tr><td width=\"100\" valign=\"top\" bgcolor=\"999966\">" $day "</td></tr>";
      echo 
"<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
      echo 
"</table></td>";
      
}else{
      echo 
"<td  valign=\"top\"><table border=\"0\" align=\"center\">";
      echo 
"<tr><td width=\"100\" valign=\"top\" bgcolor=\"cccc99\">" $day "</td></tr>";
      echo 
"<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
      echo 
"</table></td>";


Am i doing it right ?
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 12-02-2008, 12:14 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Haven't tested it though, but it looks correct!
__________________
Tanax is offline  
Reply With Quote
Old 12-02-2008, 04:10 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Peuplarchie: you might also want to check the year.

PHP Code:
if ($month == date("m") && $day == date("d")){ 


becomes:

PHP Code:
if ($month == date("m") && $day == date("d") && $year == date('Y')){ 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 12-02-2008, 07:50 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I created a calendar class for TalkPHP. Although I never released it. I should do as it's very in-depth! The function I used for detecting if it is the weekend or not, is the following:

php Code:
public function isWeekend()
{
    list($iDay, $iMonth, $iYear) = explode(' ', date('d m Y', $this->m_iDate));
    $szDay = date('D', mktime(0, 0, 0, $iMonth, $iDay, $iYear));
   
    if($szDay == 'Sat' || $szDay == 'Sun')
    {
        return true;
    }
   
    return false;
}

The member variable $this->m_iDate is nothing more than a UNIX timestamp. This can obviously be created using time()! Perhaps somebody knows of a better way, however. In which case, I would love to hear it, as I love dealing with dates.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-05-2008, 02:22 PM   #6 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Wouldn't this be easier Wildhoney?

PHP Code:
public function isWeekend()
{
    
$iDay date('N'$this->m_iDate);
    
    if(
$iDay == || $iDay == 7)
    {
        return 
true;
    }
    
    return 
false;

I see no reason to use mktime here. Also, I prefer to use integers for days (like monday = 1, sunday = 7).
maZtah is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
date/mktime for next week? oMIKEo Absolute Beginners 9 01-29-2013 09:35 AM


All times are GMT. The time now is 03:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design