Skip to content

Instantly share code, notes, and snippets.

@faisalman
Created May 10, 2012 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save faisalman/2652218 to your computer and use it in GitHub Desktop.
Save faisalman/2652218 to your computer and use it in GitHub Desktop.
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