{"id":562,"date":"2009-04-08T00:53:06","date_gmt":"2009-04-07T23:53:06","guid":{"rendered":"http:\/\/dasini.net\/blog\/?p=562"},"modified":"2019-06-05T12:06:45","modified_gmt":"2019-06-05T11:06:45","slug":"numero-de-semaine","status":"publish","type":"post","link":"https:\/\/dasini.net\/blog\/2009\/04\/08\/numero-de-semaine\/","title":{"rendered":"Num\u00e9ro de semaine calendaire MySQL"},"content":{"rendered":"

MySQL poss\u00e8de un grand nombre de fonctions pour g\u00e9rer les dates et le temps<\/a>. Il est possible de r\u00e9cup\u00e9rer le num\u00e9ro calendaire d’une semaine avec la fonction week<\/a>. Dimanche 5 avril nous \u00e9tions semaine 14. La fonction week nous le confirme:<\/p>\n

mysql> SELECT week('2009-04-05');\n+--------------------+\n| week('2009-04-05') |\n+--------------------+\n|                 14 |\n+--------------------+<\/pre>\n

Lundi 6 avril, nouvelle semaine, on passe donc \u00e0 la semaine 15:<\/p>\n

mysql> SELECT week('2009-04-06');\n+--------------------+\n| week('2009-04-06') |\n+--------------------+\n|                 14 |\n+--------------------+<\/pre>\n

Souci !!! Le r\u00e9sultat n’est pas celui esp\u00e9r\u00e9 (14 au lieu de 15). En fait la fonction week<\/em> prend un deuxi\u00e8me param\u00e8tre optionnel, qui permet de \u00ab\u00a0r\u00e9gler la pr\u00e9cision<\/em>\u00a0\u00bb (compter sur 53 ou 54 semaines, commencer la semaine un dimanche ou un lundi…) bref elle est compl\u00e8te et complexe…<\/p>\n

Le r\u00e9glage usuel est de mettre le deuxi\u00e8me param\u00e8tre \u00e0 3<\/strong><\/span> ! ou alors d’utiliser la fonction WEEKOFYEAR<\/span><\/strong><\/a>.<\/p>\n

mysql> SELECT weekofyear('2009-04-05');\n+--------------------------+\n| weekofyear('2009-04-05') |\n+--------------------------+\n|                       14 |\n+--------------------------+<\/pre>\n
mysql> SELECT weekofyear('2009-04-06');\n+--------------------------+\n| weekofyear('2009-04-06') |\n+--------------------------+\n|                       15 |\n+--------------------------+<\/pre>\n","protected":false},"excerpt":{"rendered":"

MySQL poss\u00e8de un grand nombre de fonctions pour g\u00e9rer les dates et le temps. Il est possible de r\u00e9cup\u00e9rer le num\u00e9ro calendaire d’une semaine avec la fonction week. Dimanche 5 avril nous \u00e9tions semaine 14. La fonction week nous le confirme:<\/p>\n

mysql> SELECT week(‘2009-04-05’);<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[88,8],"tags":[248,119,117,118],"class_list":["post-562","post","type-post","status-publish","format-standard","hentry","category-astuce","category-mysql","tag-astuce","tag-semaine-calendaire","tag-week","tag-weekofday"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9LfWW-94","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/comments?post=562"}],"version-history":[{"count":12,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/562\/revisions"}],"predecessor-version":[{"id":3155,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/562\/revisions\/3155"}],"wp:attachment":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/media?parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/categories?post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/tags?post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}