{"id":6696,"date":"2024-11-24T10:00:53","date_gmt":"2024-11-24T01:00:53","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6696"},"modified":"2024-08-29T13:10:46","modified_gmt":"2024-08-29T04:10:46","slug":"post-6696","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6696","title":{"rendered":"MySQL\u306b\u3066date\u578b\u306e\u30ab\u30e9\u30e0\u304b\u3089\u66dc\u65e5\u3092\u8a08\u7b97\u3057\u8868\u793a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>MySQL\u306b\u3066date\u3082\u3057\u304f\u306fdatetime\u578b\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u3066\u66dc\u65e5\u3082\u3042\u308f\u305b\u3066\u8868\u793a\u3057\u305f\u3044\u3088\u3046\u306a\u5834\u5408\u3001\u66dc\u65e5\u90e8\u5206\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306fPHP\u3067\u5bfe\u5fdc\u3057\u3066\u3044\u305f\u3002\u4eca\u66f4\u306a\u304c\u3089\u3060\u3051\u3069MySQL\u3067\u5bfe\u5fdc\u3067\u304d\u308b\u3093\u3058\u3083\u306a\u3044\u306e\u304b\u3068\u601d\u3063\u3066\u8abf\u3079\u305f\u3068\u3053\u308d\u7c21\u5358\u306b\u5bfe\u5fdc\u3067\u304d\u305f\u3002\u4ee5\u4e0b\u306b\u5bfe\u5fdc\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i\">\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\u3068\u30c7\u30fc\u30bf\u5185\u5bb9<\/span><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mysql&gt; SHOW COLUMNS FROM `test_table`;\r\n+-------+------+------+-----+---------+----------------+\r\n| Field | Type | Null | Key | Default | Extra          |\r\n+-------+------+------+-----+---------+----------------+\r\n| id    | int  | NO   | PRI | NULL    | auto_increment |\r\n| ymd   | date | NO   |     | NULL    |                |\r\n+-------+------+------+-----+---------+----------------+\r\n\r\nmysql&gt; SELECT * FROM `test_table`;\r\n+----+------------+\r\n| id | ymd        |\r\n+----+------------+\r\n|  1 | 2024-01-01 |\r\n|  2 | 2024-01-02 |\r\n|  3 | 2024-01-03 |\r\n|  4 | 2024-01-04 |\r\n|  5 | 2024-01-05 |\r\n|  6 | 2024-01-06 |\r\n|  7 | 2024-01-08 |\r\n+----+------------+<\/pre>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-2\">\u5bfe\u5fdc\u65b9\u6cd5<\/span><\/h2>\n<h3><span id=\"SQL\">SQL\u6587<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT `ymd`,\r\n    CASE DAYOFWEEK(`ymd`) \r\n        WHEN 1 THEN '\u65e5' \r\n        WHEN 2 THEN '\u6708' \r\n        WHEN 3 THEN '\u706b' \r\n        WHEN 4 THEN '\u6c34' \r\n        WHEN 5 THEN '\u6728' \r\n        WHEN 6 THEN '\u91d1' \r\n        WHEN 7 THEN '\u571f' \r\n    END AS week \r\nFROM `test_table`;<\/pre>\n<h3><span id=\"i-3\">\u51fa\u529b\u7d50\u679c<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">+------------+------+\r\n| ymd        | week |\r\n+------------+------+\r\n| 2024-01-01 | \u6708   |\r\n| 2024-01-02 | \u706b   |\r\n| 2024-01-03 | \u6c34   |\r\n| 2024-01-04 | \u6728   |\r\n| 2024-01-05 | \u91d1   |\r\n| 2024-01-06 | \u571f   |\r\n| 2024-01-08 | \u6708   |\r\n+------------+------+<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<h3>DAYOFWEEK<\/h3>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/date-and-time-functions.html#function_dayofweek\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/date-and-time-functions.html#function_dayofweek<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u306b\u3066date\u3082\u3057\u304f\u306fdatetime\u578b\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u3066\u66dc\u65e5\u3082\u3042\u308f\u305b ... <\/p>\n","protected":false},"author":1,"featured_media":1072,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,66],"tags":[],"class_list":["post-6696","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-database"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6696"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6696\/revisions"}],"predecessor-version":[{"id":6697,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6696\/revisions\/6697"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1072"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}