WEEK(NOW()) en date('W')

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Whinger de PHPer

Whinger de PHPer

14/04/2008 20:19:00
Quote Anchor link
Beste PHP'ers en MySQL'ers,

Ik ben op zoek naar een exacte functie van WEEK() in php waarbij de weken precies hetzelfde zijn.

Het probleem waar ik op het moment mee zit is dat als ik
WEEK(NOW()) doe, hij 15 zegt en wanneer ik
date('W') in php doe, hij 16 weergeeft.

Nu ben ik er van op de hoogte dat je bij week enkele mode's in kan geven:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
  First day    
Mode of week Range Week 1 is the first week  
0 Sunday 0-53 with a Sunday in this year
1 Monday 0-53 with more than 3 days this year
2 Sunday 1-53 with a Sunday in this year
3 Monday 1-53 with more than 3 days this year
4 Sunday 0-53 with more than 3 days this year
5 Monday 0-53 with a Monday in this year
6 Sunday 1-53 with more than 3 days this year
7 Monday 1-53 with a Monday in this year
?>

maar ik vraag mij dus af welke mode PHP aanhoud, kennelijk is dit dus niet de standaard mode.

Alvast bedankt,

Whinger
 
PHP hulp

PHP hulp

24/04/2024 12:58:52
 
Frank -

Frank -

14/04/2008 20:20:00
Quote Anchor link
En wat zegt de PHP-handleiding?
 
- SanThe -

- SanThe -

14/04/2008 20:26:00
Quote Anchor link
MySQL

#

WEEK(date[,mode])

This function returns the week number for date. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53. If the mode argument is omitted, the value of the default_week_format system variable is used. See Section 5.1.3, “System Variables”.

The following table describes how the mode argument works.
First day
Mode of week Range Week 1 is the first week …
0 Sunday 0-53 with a Sunday in this year
1 Monday 0-53 with more than 3 days this year
2 Sunday 1-53 with a Sunday in this year
3 Monday 1-53 with more than 3 days this year
4 Sunday 0-53 with more than 3 days this year
5 Monday 0-53 with a Monday in this year
6 Sunday 1-53 with more than 3 days this year
7 Monday 1-53 with a Monday in this year

mysql> SELECT WEEK('1998-02-20');
-> 7
mysql> SELECT WEEK('1998-02-20',0);
-> 7
mysql> SELECT WEEK('1998-02-20',1);
-> 8
mysql> SELECT WEEK('1998-12-31',1);
-> 53

Note that if a date falls in the last week of the previous year, MySQL returns 0 if you do not use 2, 3, 6, or 7 as the optional mode argument:

mysql> SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
-> 2000, 0

One might argue that MySQL should return 52 for the WEEK() function, because the given date actually occurs in the 52nd week of 1999. We decided to return 0 instead because we want the function to return “the week number in the given year.” This makes use of the WEEK() function reliable when combined with other functions that extract a date part from a date.

If you would prefer the result to be evaluated with respect to the year that contains the first day of the week for the given date, use 0, 2, 5, or 7 as the optional mode argument.

mysql> SELECT WEEK('2000-01-01',2);
-> 52

Alternatively, use the YEARWEEK() function:

mysql> SELECT YEARWEEK('2000-01-01');
-> 199952
mysql> SELECT MID(YEARWEEK('2000-01-01'),5,2);
-> '52'
 
Whinger de PHPer

Whinger de PHPer

14/04/2008 20:46:00
Quote Anchor link
bedankt voor jullie hulp :)
dit was ook voldoende geweest hoor:
the ISO week number corresponds to WEEK(date, 3)
 
Zand

Zand

28/04/2008 18:27:00
Quote Anchor link
Vreemd genoeg krijg ik als ik
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
$sql="SELECT week(current_DATE), 1";
invoer in een PHP document geen resultaat. Weet iemand hoe ik dit oplos?
Gewijzigd op 01/01/1970 01:00:00 door Zand
 
Erwin Nieuwenhuis

Erwin Nieuwenhuis

28/04/2008 18:28:00
Quote Anchor link
je selecteert deze week, en het getal 1. maar waar selecteer je het uit, en waarschijlijk bedoel je een WHERE statement
 
Zand

Zand

28/04/2008 18:45:00
Quote Anchor link
erwin schreef op 28.04.2008 18:28:
je selecteert deze week, en het getal 1. maar waar selecteer je het uit, en waarschijlijk bedoel je een WHERE statement


Ik dacht hetzelfde te doen als wat in het voorbeeld beschreven werd.
# [
mysql> SELECT WEEK('2000-01-01',2);
-> 52
]

Maar dan door de datum in te stellen op de 'huidige datum'.
Wel door eerste verbinding te maken met de database, maar zonder een tabel te selecteren.
Gewijzigd op 01/01/1970 01:00:00 door Zand
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.