IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[Dates] Aide pour calendrier


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 121
    Points : 73
    Points
    73
    Par défaut [Dates] Aide pour calendrier
    J'ai cherché un script de calendrier le plus simple possible afin le comprendre correctement. J'ai changé quelque petite chose. Le voila:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
     
    <?php 
     
    //This gets today's date 
    $date =time ();
     
    //This puts the day, month, and year in seperate variables 
    $day = date('d', $date);
    $month = date('m', $date);
    $year = date('Y', $date);
     
    //Here we generate the first day of the month 
    $first_day = mktime(0,0,0,$month, 1, $year);
     
     
    //This gets us the month name 
    $title = date('n', $first_day);
     
     
     
     
    if ($title == 1)
    {
    $title = 'Janvier';
    }
    elseif ($title == 2)
    {
    $title = 'Février';
    }
    elseif ($title == 3)
    {
    $title = 'Mars';
    }
    elseif ($title == 4)
    {
    $title = 'Avril';
    }
    elseif ($title == 5)
    {
    $title = 'Mai';
    }
    elseif ($title == 6)
    {
    $title = 'Juin';
    }
    elseif ($title == 7)
    {
    $title = 'Juillet';
    }
    elseif ($title == 8)
    {
    $title = 'Aout';
    }
    elseif ($title == 9)
    {
    $title = 'Septembre';
    }
    elseif ($title == 10)
    {
    $title = 'octobre';
    }
    elseif ($title == 11)
    {
    $title = 'Novembre';
    }
    else
    {
    $title = 'Décembre';
    }
     
     
     
     
     
     
     
     
     
     
     
     
    //Here we find out what day of the week the first day of the month falls on 
    $day_of_week = date('D', $first_day);
     
     
    //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
    switch($day_of_week)
    { 
    case "Sun": $blank = 0; break; 
    case "Mon": $blank = 1; break; 
    case "Tue": $blank = 2; break; 
    case "Wed": $blank = 3; break; 
    case "Thu": $blank = 4; break; 
    case "Fri": $blank = 5; break; 
    case "Sat": $blank = 6; break; 
    }
     
    //We then determine how many days are in the current month
    $days_in_month = cal_days_in_month(0, $month, $year);
     
     
     
     
     
     
     
    //Here we start building the table heads 
    echo "<table border=0 width=350 height=300>";
    echo "<tr><th colspan=7> $title $year </th></tr>";
    echo "<tr><td width=50 align=center>Di</td><td width=50 align=center>Lu</td><td width=50 align=center>Ma</td><td width=50 align=center>Me</td><td width=50 align=center>Je</td><td width=50 align=center>Ve</td><td width=50 align=center>Sa</td></tr>";
     
    //This counts the days in the week, up to 7
    $day_count = 1;
     
    echo "<tr>";
    //first we take care of those blank days
    while ( $blank > 0 ) 
    { 
    echo "<td></td>"; 
    $blank = $blank-1; 
    $day_count++;
    } 
     
     
     
     
     
     
     
    //sets the first day of the month to 1 
    $day_num = 1;
     
    //count up the days, untill we've done all of them in the month
    while ( $day_num <= $days_in_month ) 
    { 
    echo "<td align=\"center\"> $day_num </td>"; 
    $day_num++; 
    $day_count++;
     
    //Make sure we start a new row every week
    if ($day_count > 7)
    {
    echo "</tr><tr>";
    $day_count = 1;
    }
    } 
     
     
     
     
    //Finaly we finish out the table with some blank details if needed
    while ( $day_count >1 && $day_count <=7 ) 
    { 
    echo "<td> </td>"; 
    $day_count++; 
    } 
     
    echo "</tr></table>"; 
     
     
     
    ?>
    Tout cela est affiché dans une div.

    Ma question est la suivante: comment affiché le jour actuel dans une autre couleur?

    Comment affiché dans d'autre div supperposé (ca c'est je sais le faire avec le css) les autres mois de l'année ?

  2. #2
    Membre à l'essai
    Inscrit en
    Juin 2008
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Juin 2008
    Messages : 19
    Points : 17
    Points
    17
    Par défaut
    salut,
    je crois qu'il suffit de faire un test si la date à afficher est égale à celle d'aujourd'hui.voila un un test qui peut résoudre ton problème j'espère:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     if( $day_num  == date("j") && $month == date("n") && $year == date("Y"))
    //si tu veut afficher la date d'aujourd'hui en rouge
    {echo "<td align=\"center\"><font color='#FF0000'> $day_num</font> </td>";}
    else
    {echo "<td align=\"center\"> $day_num</td>"; }

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 121
    Points : 73
    Points
    73
    Par défaut
    merci, ca fonctionne très bien pour le jour.

    Quelqu'un aurait une idée pour les mois de l'année.

    Je pensais à récupérer le mois actuel et de faire + 1 au mois actuel jusqu'à 12 et - 1 jusqu' 1 et de faire une boucle avec tout ca mais je vois pas comment y arriver...

Discussions similaires

  1. Besoin d'aide pour les dates
    Par Aurore_atmo dans le forum MATLAB
    Réponses: 6
    Dernier message: 03/07/2006, 15h37
  2. aide pour récupération de date
    Par tribaleur dans le forum ASP
    Réponses: 5
    Dernier message: 31/05/2006, 15h09
  3. [VB6]Aide pour mettre format date avec inputbox
    Par Geliwy77 dans le forum VB 6 et antérieur
    Réponses: 13
    Dernier message: 28/01/2006, 20h13
  4. Création requete besoin d'aide pour une date
    Par royrremi dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 14/07/2004, 22h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo