Zend - The PHP Company




Calculators

Add Code


UK Tax Week  

Type: code fragment
Added by: waveydavey
Entered: 30/01/2003
Last modified: 03/12/2004
Rating: - (fewer than 3 votes)
Views: 4863
Returns UK Tax week (according to UK Inland Revenue rules) when passed a date. Not exciting, but useful!


<?php
// PHP Function to calculate UK Inland Revenue tax week from passed date
// Parameters:
// $dd - day of month, 0-31
// $mm - month of year, 0-12
// $yy - Year (4 digits better!)
// 
// I have not implemented error checking on parameters - its down to you to make sure params are correct!
//
// Warranties - NONE, (but its not rocket science!)
//
// Copyright: D B Shields, Broadowler Systems Ltd, 2003
//
// Contact: david@broadowler.co.uk
//
// Licence : Free to use, but dont sell it! 
//
function taxweek($dd$mm$yy){
    
// Inland Revenue defined Week 1 as 6-12 April inclusive, Week 2 13-19 inclusive etc.
    // NB Day of week has NO bearing on week number - tax week may start on ANY day
    // first, stamp the supplied date
    
$now=mktime(0,0,0,$mm,$dd,$yy);
    
// next, see where april first is for supplied year
    
$apryy=$yy;
    
$apr6=mktime(0,0,0,4,6,$apryy);
    if (
$apr6>$now){
        
// we are in jan-apr, so apr1 needs to be prev year
        
$apryy--;
    }
    
$apr6=mktime(0,0,0,4,6,$apryy);
    
// now how many weeks have elapsed between w1start and now ?
    
$elapsed=($now-$apr6)/86400;
    
$w=sprintf("%0.2f",$elapsed/7);
    
$wf=floor($w)+1// not cel, as breaks boundaries
    
return $wf;
}

?>


Usage Example


$w=taxweek(7,4,2002); // returns 1


Rate This Script





Search



This Category All Categories