Create a gist now

Instantly share code, notes, and snippets.

Get ISO-8601 week number for a given date in PHP
<?php
/**
* Get ISO-8601 week number for a given date
*
* @author Faisalman <fyzlman@gmail.com>
* @link http://gist.github.com/faisalman
* @link http://en.wikipedia.org/wiki/ISO_week_date
* @param $y int year
* @param $m int month
* @param $d int day
* @return int week number
*/
function get_weekth($y, $m, $d)
{
return intval(date('W',strtotime($y.'-'.$m.'-'.$d)));
}
/*
* Usage example:
* echo get_weekth(2010,12,26); // 51
* echo get_weekth(2011,1,1); // 52
* echo get_weekth(2011,1,3); // 1
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment