WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Function get_week_number which returns the week number of the given date according to ISO 8601:1988, also includes a function is_leap_year.
Categories : Date Time, PHP Update Picture
Stefan Rצhrich
Date : Jan 17th 1999
Grade : 2 of 5 (graded 3 times)
Viewed : 5181
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Stefan Rצhrich
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
/* weeknumber.php3

(int) get_week_number($timestamp)

Week number of year with Monday as first day of the week
(1...53). If the week containing January 1 has four or more days
in the new year, then it is considered week 1; otherwise, it is
week 53 of the previous year, and the next week is week 1. (See the
ISO 8601: 1988 standard.)

Adapted from GNU sh-utils for PHP3 by Stefan Rhrich, sr@linux.de,
http://home.pages.de/~sr/.

*/

function is_leap_year($year) {
if ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
return 1;
} else {
return 0;
}
}

/*
#define ISO_WEEK_START_WDAY 1 // Monday
#define ISO_WEEK1_WDAY 4 // Thursday
#define YDAY_MINIMUM (-366)
int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
return (yday
- (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
+ ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
*/

function iso_week_days($yday, $wday) {
return $yday - (($yday - $wday + 382) % 7) + 3;
}

function get_week_number($timestamp) {

$d = getdate($timestamp);

$days = iso_week_days($d[ "yday"], $d[ "wday"]);

if ($days < 0) {
$d[ "yday"] += 365 + is_leap_year(--$d[ "year"]);
$days = iso_week_days($d[ "yday"], $d[ "wday"]);
} else {
$d[ "yday"] -= 365 + is_leap_year($d[ "year"]);
$d2 = iso_week_days($d[ "yday"], $d[ "wday"]);
if (0 <= $d2) {
/* $d["year"]++; */
$days = $d2;
}
}

return (int)($days / 7) + 1;
}
?>



Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes
Calendars to choose a range of dates , reservation events ...
Categories : PHP, Calendar, Java Script, Date Time
Function to convert Arabic numbers into Roman Numerals
Categories : Algorithms, PHP, Date Time
function to generate calendars on the fly.
Categories : Calendar, PHP, Date Time
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page.
Categories : PHP, Date Time, Beginner Guides, Web Design
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
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
PHP Calendar Web App
Categories : PHP, Databases, MySQL, Date Time, Calendar
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
calculus of the eastersunday
Categories : BC math, PHP, Date Time, Databases
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
 Thomas Kunth wrote :766
You say that the result would be 53 if week containing January 1st doesn`t have at least four days in the new year.

This may not be correct:
E.g. January 1st, 2000 is week 52 of 1999.

As you see here it would be cool if you provide a function the related year...