WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 : 4662
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 
 

<?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 Röhrich, 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;
}
?>



Function to convert Arabic numbers into Roman Numerals
Categories : Algorithms, PHP, Date Time
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
function to generate calendars on the fly.
Categories : Calendar, PHP, Date Time
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
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
calculus of the eastersunday
Categories : BC math, PHP, Date Time, Databases
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP
Monthly and Daily Upcoming Events calendar.
Categories : Date Time, PostgreSQL, PHP, Calendar, Databases
Website colour changer
Categories : PHP, HTML and PHP, Date Time
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
PHP Round Clock - Must have Gif support to use this.
Categories : PHP, Date Time, Graphics
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
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...