weeks in a year


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

hi,

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

<?php
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 ???

thanks

No comments posted yet

Your Answer:

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

Insert to MySQL inside foreach
Hey.
I am parsing some html, and putting inside an html db.
I need to create a randomized inte

mysqli_fetch_assoc returns multiple arrays, how to return a single array
Hello, I am using mysqli_fetch_assoc which is returning multiple rows, so it looks like:

Code

convert static html data into dynamic
hi all

i need to convert a website which has static above 2000 articles into dynamic and add

Setting condidtions for an input box
Hi all,

I would like to set a condition in a txt box that says the number a user enters has t

Production of mango in processing industry
Hi,

We have one scenario ,company is in process industry,they are manufacturing MANGO pul

Oracle Text CTX_DOC.snippet slow
I have a table (FILE_TABLE) that contains a blob column (ft_file) and I have created the following O

Hits this week counter
I have a counter on my site that tracks hits, IP's, etc. into a mySQL database. It also includes the

php/xmlrpc class issue
I am working on xml-rpc in php to start with.

I have a class that only has variables defined

Please help understand this code
I noticed the index page on my site was modified this morning and found this code inserted at the bo

Install page
How do I make it so when a user submits information on the Install page, it'll right it into the cor

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