WEEK

Sintassi

WEEK(data[, modalita])

Spiegazione

Questa funzione restituisce il numero della settimana relativo a date. La forma a due argomenti di WEEK() permette di specificare se la settimana inizia di domenica o di lunedì e se il valore restituito deve essere nell'intervallo da 0 a 53 o da 1 a 53. Se l'argomento modalita è omesso, viene usato il valore di default_week_format.

Modalità

ModalitaPrimo giornoIntervalloSett 1 è la prima con
0Sunday0-53una domenica
1Monday0-53più di 3 giorni
2Sunday1-53una domenica
3Monday1-53più di 3 giorni
4Sunday0-53più di 3 giorni
5Monday0-53un lunedì
6Sunday1-53più di 3 giorni
7Monday1-53un lunedì

Esempi

MariaDB [(none)]> SELECT WEEK('2008-02-20');
+--------------------+
| WEEK('2008-02-20') |
+--------------------+
|                  7 |
+--------------------+

MariaDB [(none)]> SELECT WEEK('2008-02-20',0);
+----------------------+
| WEEK('2008-02-20',0) |
+----------------------+
|                    7 |
+----------------------+

MariaDB [(none)]> SELECT WEEK('2008-02-20',1);
+----------------------+
| WEEK('2008-02-20',1) |
+----------------------+
|                    8 |
+----------------------+

MariaDB [(none)]> SELECT WEEK('2008-12-31',0);
+----------------------+
| WEEK('2008-12-31',0) |
+----------------------+
|                   52 |
+----------------------+

MariaDB [(none)]> SELECT WEEK('2008-12-31',1);
+----------------------+
| WEEK('2008-12-31',1) |
+----------------------+
|                   53 |
+----------------------+
CREATE TABLE t1 (d DATETIME);
INSERT INTO t1 VALUES
    ("2007-01-30 21:31:07"),
    ("1983-10-15 06:42:51"),
    ("2011-04-21 12:34:56"),
    ("2011-10-30 06:31:41"),
    ("2011-01-30 14:03:25"),
    ("2004-10-07 11:19:34");
MariaDB [test]> SELECT d, WEEK(d,0), WEEK(d,1) from t1;
+---------------------+-----------+-----------+
| d                   | WEEK(d,0) | WEEK(d,1) |
+---------------------+-----------+-----------+
| 2007-01-30 21:31:07 |         4 |         5 |
| 1983-10-15 06:42:51 |        41 |        41 |
| 2011-04-21 12:34:56 |        16 |        16 |
| 2011-10-30 06:31:41 |        44 |        43 |
| 2011-01-30 14:03:25 |         5 |         4 |
| 2004-10-07 11:19:34 |        40 |        41 |
+---------------------+-----------+-----------+
6 rows in set (0.00 sec)

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.