Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Get week number Jump to:  
Category: >> PHP Code >> Get week number Bookmark and Share

<< lastnext >>

Snippet Name: Get week number

Description: This function returns the week number of the given date according to ISO 8601-1988.

Also see:
» Call a PHP function when clicking on a...

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?PHP 
 
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; 
} 
?>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 66 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?