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

Display data returned from Ajaxservices!!
I have a question about displaying results using ajax. I have part of the code below.
$.ajax({

Help with explandable category tree
I have the below query:

SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.categ

Get relative path from absolute path
How would one go about getting the relative path to a file from its absolute path?

data type in column definition
Hi,
I create a table with column called "Direction of Travel code ".
The travel codes in t

Files in current folder. Should be an easy fix.
Never mind. I've asked about this before and just found my answer. Anyway to delete this?

Wrong Info sent Using $get in form
Hi i have this code that i tried to make to send some info from one page to aother with lots of ppls

help connecting a form to php and then emailing the form
Ok. So, I made a form, and I need help to where when submitted, I get an email with the submitted de

Creating a function
Basically i wanna put all this code in a seperate file

Code: <?php

I need desperate help with this php code integrated with flash please
Can someone please help me with this php code which I have been stuck on for weeks . I am trying to

form help
this doesn't work. i want the form action to go the location.href of the submit button chosen.. how

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