weeks in a year

Posted on 16th Feb 2014 07:03 pm by admin


i found this snippet on php.net
QuoteFor the week number for weeks starting on Sunday:

function week_of_year($month, $day, $year) {

$day_of_year = date('z', mktime(0, 0, 0, $month, $day, $year));

/* Days in the week before Jan 1. If you want weeks to start on Monday make this (x + 6) % 7 */
$days_before_year = date('w', mktime(0, 0, 0, 1, 1, $year));

$days_left_in_week = 7 - date('w', mktime(0, 0, 0, $month, $day, $year));

/* find the number of weeks by adding the days in the week before the start of the year, days up to $day, and the days left in this week, then divide by 7 */
return ($days_before_year + $day_of_year + $days_left_in_week) / 7;


so if i go : week_of_year(1, 3, 2010) (sunday)

the week shows as 1, because the script is set to begin new week on sunday,

however i am confused by his instruction " (x + 6) % 7 " to have the week start on a monday

what part of the script do i apply this equation ???


No comments posted yet

Your Answer:

Login to answer
142 Like 13 Dislike
Previous forums Next forums
Other forums

How can I get my program to read a larger array ??

I have this program that reads from an array to do calculations. The array are just t

LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a

Which practice of iteration through containers is preferred
In the "real world" what kind of loop do most people use to iterate through a container like a vecto

values in array being escaped
I would like to submit some values - back to the same form for checking before processing...

I have a parse error in this query help..
Code: $query1="INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS

Play Free Quiz and Win Cash