note 66183 added to function.date
| From: | bertrand at triomphe dot ca | Date: | Tue, 16 May 2006 18:57:48 +0000 |
| Subject: | note 66183 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111401@lists.php.net to get a copy of this message | ||
Here's a function that will return the date of the next weekday. To put you in context, I have
a website that needs to post every tuesday ("mardi" in french) a new pdf file on the front
page. Via the web admin, the user' date fields will be already filled with the next Tuesdays
dates. You can pass current date with this call:
retournerDateProchainJourSemaine(date("Y"), date("m"), date("d"), 2);
The above will tell you the date of the next tuesday (2).
You can also seek the next day after the day found, like the monday (6) after the tuesday found,
with this call:
retournerDateProchainJourSemaine(date("Y"), date("m"), date("d"), 2,
6);
/*/////////////////////////
/ function retournerDateProchainJourSemaine (créé par Bertrand Lirette, 2006-03-22)
/
/ Fonction qui retourne le prochain jour de la semaine suivant la date soumise. Peut aussi retourner
/ un jour suivant le jour trouvé.
/ $intAnnee = chiffre représentant l'année (ex. 2006)
/ $intMois = chiffre représentant le mois (ex. 5)
/ $intJour = chiffre représentant le jour (ex. 15)
/ $intProchainJourSemaine = ordre du jour voulu (ex. mardi = 2)
/ $intNbJoursApres = nombre du jour après la date trouvé (ex. 6 pour trouver le lundi
suivant la date trouvée)
///////////////////////////////////////////////////////////////////*/
function retournerDateProchainJourSemaine($intAnnee, $intMois, $intJour, $intProchainJourSemaine,
$intNbJoursApres = 0)
{
// trouve le jour de semaine du jour présent
$intMaintenantJourSemaine = date("w", mktime(0,0,0,$intMois,$intJour,$intAnnee));
// calcule la différence entre les deux jours
$intDifference = $intProchainJourSemaine - $intMaintenantJourSemaine;
// si on est le jour, prendre la prochaine occurence
if($intDifference < 0)
{
$intNbJours = 7 + $intDifference;
}
else if($intDifference > 0)
{
$intNbJours = $intDifference;
}
else if($intDifference == 0)
{
$intNbJours = 7;
};
$datProchaineDate = date('Y-m-d',mktime(0,0,0,$intMois,$intJour + $intNbJours +
$intNbJoursApres,$intAnnee));
return $datProchaineDate;
};
Feel free to comment, debug, email me if you find it usefull! It'd be appreciated! Hope this
will help at least one user! ;)
----
Server IP: 66.207.199.35
Probable Submitter: 69.157.147.182
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/note/edit/66183
Del: integrated -- http://master.php.net/note/delete/66183/integrated
Del: useless -- http://master.php.net/note/delete/66183/useless
Del: bad code -- http://master.php.net/note/delete/66183/bad+code
Del: spam -- http://master.php.net/note/delete/66183/spam
Del: non-english -- http://master.php.net/note/delete/66183/non-english
Del: in docs -- http://master.php.net/note/delete/66183/in+docs
Del: other reasons-- http://master.php.net/note/delete/66183
Reject -- http://master.php.net/note/reject/66183
Search -- http://master.php.net/manage/user-notes.php