FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Get week number from date





devroom
I have searched for hours for a code but i couldnt find one. Does anybody knows or has a code which can calculate a code from a date
example

date: 30/11/2006 <- enter date
[get week] <-button
week: .... <-gives the weeknumber

Thx and grtz

Ps. for the moderators. I have also created a topic in the script-forum. Because there can be 2 ways.
hexkid
devroom wrote:
date: 30/11/2006 <- enter date
[get week] <-button
week: .... <-gives the weeknumber


date()
Code:
<?php
$date = mktime(0, 0, 0, 11, 30, 2006);
$week = (int)date('W', $date);
?>
devroom
hexkid wrote:
devroom wrote:
date: 30/11/2006 <- enter date
[get week] <-button
week: .... <-gives the weeknumber


date()
Code:
<?php
$date = mktime(0, 0, 0, 11, 30, 2006);
$week = (int)date('W', $date);
?>


Thx for the reply, but it isnt working proparly:
Code:
<?php
$date = mktime(0, 0, 0, 01, 01, 2006);
$week = (int)date('W', $date);
echo "Weeknummer: ".$week;
?>

January 1 2006 gives weeknumber 52. So far i know its number 1 Cool
Maybe im doing something wrong?
muggle
devroom wrote:
January 1 2006 gives weeknumber 52. So far i know its number 1 Cool
Maybe im doing something wrong?

Yes, you miss something. January 1, 2006 is Sunday. According the description of a date() function http://ca.php.net/manual/en/function.date.php
Quote:
W ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)

it's in fact the latest week in the 2005, so the answer is correct.
hexkid
devroom wrote:
January 1 2006 gives weeknumber 52.

muggle already answered you.

But you have another option: get the date for the start of the year, get the date you want, subtract, divide by a week in seconds (7 * 24 * 60 * 60), adjust result.
Code:
<?php
$year = 2006;
$Jan1 = gmmktime(0, 0, 0, 1, 1, $year);
$mydate = gmmktime(0, 0, 0, 11, 30, $year);
$delta = (int)(($mydate - $Jan1) / (7 * 24 * 60 * 60)) + 1;
echo 'weeknumber: ', $delta;
?>

Notice I used gmmktime() to avoid possible (though unlikely) errors due to daylight savings time.
devroom
Thx all for your reply's. But i would rather have it in javascript Cool
Because then the weeknummer can be changed instantly

If its possible in javascript please help me out http://www.frihost.com/forums/vt-49453.html

If it is not possble also thx and ill will use the php Very Happy
Related topics
can anyone explain me what happens?
It's 'Let's Roll', NOT 'Let's roll over'
When dating a new girl, how long do you wait before you kiss
A ActionScript,showing a running date.
New Windows Vista Test Build Expected Next Week
War on Terror?
sms jokes
sms jokes
How real id will effect you
PHP Calendar Bug
Get week number from date
Number or date/time field for timestamp?
About some beliefs from Bible...
Problem with my script....
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.