Datumfunktion

Databaser & SQL

2 svar · 236 visningar · startad av Marcus

Medlem sedan juli 2000449 inlägg
Trådstart#1

Hur kan man på ett smidigt sätt få reda på vilken vecka det är? T.ex. I databasen står det 2001-04-09, kan jag på något sätt få fram vilken vecka detta är?

Medlem sedan dec. 200012 464 inlägg
#2

Ur mysqls dokumentation

WEEK(date)
WEEK(date,first)
With a single argument, returns the week for date, in the range 0 to 53 (yes, there may be the beginnings of a week 53), for locations where Sunday is the first day of the week. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday. The week starts on Sunday if the second argument is 0, on Monday if the second argument is 1:

mysql> select WEEK('1998-02-20');
-> 7
mysql> select WEEK('1998-02-20',0);
-> 7

Medlem sedan juli 2000449 inlägg
#3

Tack så mycket.

255 ms totalt · 4 externa anrop · v20260731065814-full.d34c6d5a
119 ms — deklarationer (db)
0 ms — hämta statistik (cache)
132 ms — hämta tråd, inlägg och bilagor (db)
120 ms — ändringar (db)