|
|
|
| Title : |
Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays. |
| Categories : |
Calendar, Date Time, PHP, Databases, MySQL |
 Kok Hoo |
| Date : |
Mar 02nd 2002 |
| Grade : |
3 of 5 (graded 9 times) |
| Viewed : |
20889 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Kok Hoo |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?
//
// count how many weeks in the month have a specified day, such as Monday.
// we know there will be 4 or 5, so no need to check for $weeks<4 or $weeks>5
//
// Initial formula doesn't work well, so I "reversed-engineered" to get the formula.
// 0 - Sunday,...,6 - Saturday
for ($year = 2001; $year <= 2037; $year++)
{
for ($month = 1; $month <= 12; $month++)
{
$num_of_days = date("t", mktime(0,0,0,$month,1,$year));
echo "<HR> Month=$month Year=$year <BR>";
echo "Number of days = $num_of_days <BR>";
$firstdayname = date("D", mktime(0, 0, 0, $month, 1, $year));
$firstday = date("w", mktime(0, 0, 0, $month, 1, $year));
$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
echo "First day of the month = $firstday,$firstdayname <BR> ";
for ($day_of_week = 0; $day_of_week <= 6; $day_of_week++)
{
if ($firstday > $day_of_week) {
// means we need to jump to the second week to find the first $day_of_week
$d = (7 - ($firstday - $day_of_week)) + 1;
} elseif ($firstday < $day_of_week) {
// correct week, now move forward to specified day
$d = ($day_of_week - $firstday + 1);
} else {
// my "reversed-engineered" formula
if ($lastday==28) // max of 4 occurences each in the month of February with
28
days
$d = ($firstday + 4);
elseif ($firstday==4)
$d = ($firstday - 2);
elseif ($firstday==5 )
$d = ($firstday - 3);
elseif ($firstday==6)
$d = ($firstday - 4);
else
$d = ($firstday - 1);
if ($lastday==29) // only 1 set of 5 occurences each in the month of
February with
29 days
$d -= 1;
}
$d += 28; // jump to the 5th week and see if the day exists
if ($d > $lastday) {
$weeks = 4;
} else {
$weeks = 5;
}
if ($day_of_week==0) echo "Sun ";
elseif ($day_of_week==1) echo "Mon ";
elseif ($day_of_week==2) echo "Tue ";
elseif ($day_of_week==3) echo "Wed ";
elseif ($day_of_week==4) echo "Thu ";
elseif ($day_of_week==5) echo "Fri ";
else echo "Sat ";
echo "occurences = $weeks <BR> ";
} // for $day_of_week loop
} // for $mth loop
} // for $year loop
?>
|
|
| mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | | | Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP, Date Time, Strings, MySQL, Databases | | | Data Retrieve from Mysql using AJAX with PHP Categories : PHP, AJAX, Date Time, Databases, MySQL | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | How to Convert a MySQL Timestamp to a USA Date & Time Categories : PHP, MySQL, Databases, Date Time | | | List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP | | | Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL, Date Time, PHP, Databases | | | Simple function to return the number of days in a time span between 2 given dates. Categories : PHP, Date Time, MySQL, Databases | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date. Categories : PHP, Date Time, Databases, MySQL | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | formating MySQL Timestamp to get a propper Output.
related : Timestamp, ereg_replace, mysql, substr Categories : MySQL, PHP, Date Time, Databases | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | |
|
|
|