#native_company# #native_desc#
#native_cta#

UK Tax Week Calculator

By David Shields
on January 30, 2003

Version: 0.1

Type: Function

Category: Calendars/Dates

License: Artistic License

Description: Function returns UK tak week accoring to Inland Revenue rules. Not exciting, but useful.

// 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: [email protected]
//
// 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;
}