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:
Did you know?Explore Trending and Topic pages for more stories like this.

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

How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree

Delete HTML file after loading
I have limited experience with php and its been a year or two since I've last used it. I have a sma

PHP Captcha Error help - replace the "die" command
Hi All,

I am after a bit of help with a Captcha spam protection box.

The site gave me

If a record matches an existing record do nothing
So I don't know if I should put this here or in mysql, but what my script is for is for people to ad

help with database debug pls
Parse error: syntax error, unexpected T_ELSE in /home/content/m/e/s/mesick/html/students/05/php/chec

(sub)screen resize modification doesn't work after ECC 6 EhP 4 installation
Hello,

We have previously extended the size of the custom data tab on PO transaction ME23

Problem with passing variables
I'm not really a php programmer so I'm really struggling with this issue.

I have a banner s

Array help
Hello i got this code to fetch data from database but it is not working it displays
7
Array

Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D

I'm

my sql select id and then update problem.
I need to select some auto incremented ids out of a database and then use those id in a where statem

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