{"id":703,"date":"2013-12-31T15:17:39","date_gmt":"2013-12-31T06:17:39","guid":{"rendered":"http:\/\/blog.sensuishi.net\/?p=703"},"modified":"2014-02-27T15:48:53","modified_gmt":"2014-02-27T06:48:53","slug":"post-703","status":"publish","type":"post","link":"https:\/\/blog.sensuishi.net\/?p=703","title":{"rendered":"PHP \u8a95\u751f\u65e5\u304b\u3089\u5e74\u9f62\u8a08\u7b97\u3068\u65e5\u672c\u56fd\u6cd5"},"content":{"rendered":"<p>\u4f55\u3082\u8003\u3048\u305a\u306b\u8a95\u751f\u65e5\u304b\u3089\u5e74\u9f62\u8a08\u7b97\u3092\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u3059\u3002<br \/>\n\u3057\u304b\u3057\u4f55\u3082\u8003\u3048\u306a\u3044\u3068\u8a34\u8a1f\u554f\u984c\u306b\u767a\u5c55\u3059\u308b\u306e\u304c\u5e74\u9f62\u8a08\u7b97\u3067\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>PHP\u306a\u3089<\/p>\n<p>int(([\u57fa\u6e96\u65e5]-[\u751f\u5e74\u6708\u65e5])\/10000) \u3084 floor(([\u57fa\u6e96\u65e5]-[\u751f\u5e74\u6708\u65e5])\/10000) \u3067\u8a08\u7b97\u3067\u304d\u307e\u3059\u3002<br \/>\nex : (int)((date(&#8216;Ymd&#8217;)-19901010)\/10000);<\/p>\n<p>MySQL\u306a\u3089<\/p>\n<p>SELECT (YEAR(CURDATE())-YEAR(&#8216;1990-10-10&#8217;)) &#8211; (RIGHT(CURDATE(),5)&lt;RIGHT(&#8216;1990-10-10&#8217;,5)) AS age;<\/p>\n<p>\u4ee5\u4e0a\u306a\u306e\u3067\u3059\u304c\u2026<br \/>\n1\u65e5\u305a\u308c\u307e\u3059\u3002<br \/>\n\u65e5\u672c\u306f\u3044\u308d\u3044\u308d\u3068\u3081\u3093\u3069\u304f\u3055\u3044\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u6cd5\u5f8b<br \/>\n\u25cf\u5e74\u9f62\u8a08\u7b97\u30cb\u95a2\u30b9\u30eb\u6cd5\u5f8b<br \/>\n\u660e\u6cbb35\u5e7412\u67082\u65e5\u6cd5\u5f8b\u7b2c50\u53f7 \u73fe\u884c\u6cd5\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u5e74\u9f62\u306f\u51fa\u751f\u306e\u65e5\u3088\u308a\u4e4b\u3092\u8d77\u7b97\u3059<\/li>\n<li>\u6c11\u6cd5\u7b2c143\u6761\u306e\u898f\u5b9a\u306f\u5e74\u9f62\u306e\u8a08\u7b97\u306b\u4e4b\u3092\u6e96\u7528\u3059<\/li>\n<li>\u660e\u6cbb6\u5e74\u7b2c36\u53f7\u5e03\u544a\u306f\u4e4b\u3092\u5ec3\u6b62\u3059<\/li>\n<\/ul>\n<p>\u308f\u305a\u304b54\u6587\u5b57\u306e\u6cd5\u5f8b\u3067\u30b7\u30f3\u30d7\u30eb\u306a\u306e\u3067\u3059\u304c\u3001\u3044\u308d\u3044\u308d\u3068\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u901a\u5e38\u671f\u9593\u8a08\u7b97\u306b\u304a\u3044\u3066\u300c\u8d77\u7b97\u65e5\u300d\u306f\u3001\u521d\u65e5\u3092\u7701\u3044\u3066\u7fcc\u65e5\u3068\u3059\u308b\u306e\u304c\u539f\u5247\u3067\u3059\u3002<br \/>\n\u305f\u3068\u3048\u3070\u7d50\u5a5a\u8a18\u5ff5\u65e5\u3002\u3000\u4f55\u3092\u6301\u3063\u3066\u8a18\u5ff5\u3068\u3059\u308b\u304b\u306f\u304a\u3044\u3066\u304a\u3044\u3066\u3001\u5165\u7c4d\u65e5\u304c10\u670810\u65e5\u306e\u5834\u5408\u3001\u6bce\u5e7410\u670810\u65e5\u304c\u7d50\u5a5a\u8a18\u5ff5\u65e5\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f10\u670811\u65e5\u3092\u8d77\u7b97\u65e5\u3068\u3057\u3066\u3001\u7fcc\u5e7410\u670810\u65e5\u304c\u7d50\u5a5a\u4f55\u5468\u5e74\u3068\u3057\u3066\u3044\u308b\u304b\u3089\u3067\u3059\u3002<br \/>\n\u795d\u3044\u4e8b\u3067\u8003\u3048\u305f\u5834\u5408\u3001\u8a95\u751f\u65e5\u3082\u540c\u3058\u8003\u3048\u65b9\u306a\u306e\u3067\u3059\u304c\u3001\u6cd5\u5f8b\u306f\u8d77\u7b97\u65e5\u304c\u305d\u306e\u65e5\u304c\u8d77\u7b97\u65e5\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3059\u306a\u308f\u306110\u670810\u65e5\u751f\u307e\u308c\u306a\u308910\u67089\u65e5\u306b\u6e80\u5e74\u9f62\u304c1\u3064\u52a0\u7b97\u3055\u308c\u308b\u306e\u3067\u3059\u3002<br \/>\n\u3053\u306e\u8003\u3048\u65b9\u306e\u4e0d\u4e00\u81f4\u304c\u305d\u3082\u305d\u3082\u306e\u554f\u984c\u306a\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u5e74\u9f62\u304c\u95a2\u4fc2\u3059\u308b\u6cd5\u5f8b\u306f\u305f\u304f\u3055\u3093\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u7fa9\u52d9\u6559\u80b2\u3084\u3001\u904b\u8ee2\u514d\u8a31\u53d6\u5f97\u5e74\u9f62\u3001\u9078\u6319\u6a29\u3084\u53c2\u653f\u6a29\u3001\u56fd\u5bb6\u8cc7\u683c\u306a\u3069\u5e74\u91d1\u53d7\u7d66\u5e74\u9f62\u306a\u3069\u69d8\u3005\u306a\u3068\u3053\u308d\u3067\u6cd5\u5f8b\u306b\u5e74\u9f62\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u305d\u306e\u6cd5\u5f8b\u89e3\u91c8\u306b\u3088\u308a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u304c\u5909\u308f\u308a\u307e\u3059\u3002<br \/>\n\u5177\u4f53\u7684\u306b\u8a00\u3046\u3068\u300c\u8a95\u751f\u65e5\u524d\u65e5\u300d\u3068\u300c\u8a95\u751f\u65e5\u5f53\u65e5\u300d\u304b\u3089\u52b9\u529b\u3092\u6301\u3064\u6cd5\u5f8b\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>1.\u300c\u00d7\u6b73\u306b\u9054\u3057\u305f\u65e5\u300d\u306e\u5834\u5408\u3001\u8a95\u751f\u65e5\u306e\u524d\u65e50\u6642\u304b\u3089\u52b9\u529b\u3092\u6301\u3064\u3002<br \/>\n2.\u300c\u00d7\u6b73\u4ee5\u4e0a\u300d\u300c\u00d7\u6b73\u306b\u6e80\u305f\u306a\u3044\u8005\u300d\u306a\u3069\u300c\u65e5\u300d\u3092\u542b\u307e\u306a\u3044\u5834\u5408\u3001\u6642\u9593\u5358\u4f4d\u3068\u89e3\u91c8\u3055\u308c\u5348\u5f8c12\u6642\u306b\u52b9\u529b\u3092\u6301\u3061\u307e\u3059\u3002<br \/>\n3.\u300c\u00d7\u6b73\u306b\u9054\u3057\u305f\u65e5\u306e\u7fcc\u65e5\u300d\u306f\u5358\u7d14\u306b\u8a95\u751f\u65e5\u3092\u3055\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u79c1\u305f\u3061\u304c\u65e5\u5e38\u7684\u306b\u4f7f\u3063\u3066\u3044\u308b\u5e74\u9f62\u8a08\u7b97\u306f1\u65e5\u9045\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5546\u5e97\u304c\u9867\u5ba2\u8a95\u751f\u65e5\u306b\u5e74\u9f62\u4ed8\u3067DM\u3092\u9001\u308b\u5206\u306b\u306f\u3044\u3044\u3093\u3067\u3057\u3087\u3046\u304c\u3001\u6e80\u5e74\u9f62\u306f\u8a95\u751f\u65e5\u306e\u524d\u65e5\u306b\u52a0\u7b97\u3055\u308c\u308b\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p><?php\n\nfunction getAge($birthdayDate,$anyDate,$tassuruFlg){\n\n\tif(!isset($tassuruFlg))$tassuruFlg=0;\n\t$birthdayDate=str_replace('-','',$birthdayDate);\n\t$birthdayDate=str_replace('\/','',$birthdayDate);\n\n\tif($tassuruFlg)$birthdayDate=date(\"Ymd\", strtotime(\"-1 day\" ,strtotime($birthdayDate)));\n\n\tif(isset($anyDate)){\n\t\t$anyDate=str_replace('-','',$anyDate);\n\t\t$anyDate=str_replace('\/','',$anyDate);\n\t\t$age=(int)(($anyDate-$birthdayDate)\/10000);\n\t}else{\n\t\t$age=(int)((date('Ymd')-$birthdayDate)\/10000);\n\t}\n\n\treturn $age;\n}\n\n$birthdayDate=\"19901010\";\n\n$anyDate=\"20131009\";\n$tassuruFlg=0;\necho \"$birthdayDate:$anyDate:$tassuruFlg = \".getAge($birthdayDate,$anyDate,$tassuruFlg).\"<br \/>\\n&#8221;;<br \/>\n$tassuruFlg=1;<br \/>\necho &#8220;$birthdayDate:$anyDate:$tassuruFlg = &#8220;.getAge($birthdayDate,$anyDate,$tassuruFlg).&#8221;<br \/>\\n&#8221;;<\/p>\n<p>$anyDate=&#8221;20131010&#8243;;<br \/>\n$tassuruFlg=0;<br \/>\necho &#8220;$birthdayDate:$anyDate:$tassuruFlg = &#8220;.getAge($birthdayDate,$anyDate,$tassuruFlg).&#8221;<br \/>\\n&#8221;;<br \/>\n$tassuruFlg=1;<br \/>\necho &#8220;$birthdayDate:$anyDate:$tassuruFlg = &#8220;.getAge($birthdayDate,$anyDate,$tassuruFlg).&#8221;<br \/>\\n&#8221;;<\/p>\n<p>?><\/p>\n<p>\u5b9f\u884c\u7d50\u679c<br \/>\n19901010:20131009:0 = 22<br \/>\n19901010:20131009:1 = 23<br \/>\n19901010:20131010:0 = 23<br \/>\n19901010:20131010:1 = 23<br \/>\n<a href=\"http:\/\/blog.sensuishi.net\/wp-content\/uploads\/2013\/12\/getAge.jpg\"><img loading=\"lazy\" src=\"http:\/\/blog.sensuishi.net\/wp-content\/uploads\/2013\/12\/getAge-300x114.jpg\" alt=\"getAge\" width=\"300\" height=\"114\" class=\"alignnone size-medium wp-image-715\" srcset=\"https:\/\/blog.sensuishi.net\/wp-content\/uploads\/2013\/12\/getAge-300x114.jpg 300w, https:\/\/blog.sensuishi.net\/wp-content\/uploads\/2013\/12\/getAge.jpg 378w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>MySQL\u306a\u3089<br \/>\n\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b<\/p>\n<p>SELECT (YEAR(NOW())-YEAR(&#8216;1990-10-10&#8217;)) &#8211; (DATE_FORMAT(&#8216;1990-10-10&#8217; &#8211; INTERVAL 1 DAY ,  &#8216;%m-%d&#8217; ) > DATE_FORMAT(NOW(),  &#8216;%m-%d&#8217; )) AS age;<\/p>\n<p>\u30e1\u30bf\u6587\u5b57\u306a\u3069\u3092\u5909\u306b\u30a8\u30b9\u30b1\u30fc\u30d7\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u5143\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n\u25cfdownload\u25cf<br \/>\n<a href=\"http:\/\/blog.sensuishi.net\/download\/?f=getAge.zip\" title=\"download\" target=\"_blank\">http:\/\/blog.sensuishi.net\/download\/?f=getAge.zip<\/a><\/p>\n<p>\u3053\u306e\u5e74\u9f62\u8a08\u7b97\u306b\u95a2\u3059\u308b\u6cd5\u5f8b\u3068\u5b66\u6821\u6559\u80b2\u6cd5\u306e\u95a2\u4fc2\u304b\u3089\u30014\u67081\u65e5\u751f\u307e\u308c\u306e\u4eba\u306f3\/31\u306b\u6e80\u516d\u6b73\u306b\u306a\u308a\u3001\u5b66\u6821\u6559\u80b2\u6cd5\u306b\u5b66\u5e74\u306f4\/1\uff5e\u7fcc\u5e743\/31\u3068\u3057\u3001\u4fdd\u8b77\u8005\u306f\u5b50\u5973\u306e\u6e806\u624d\u306b\u9054\u3057\u305f\u65e5\u306e\u7fcc\u65e5\u4ee5\u5f8c\u306b\u304a\u3051\u308b\u6700\u521d\u306e\u5b66\u5e74\u306e\u521d\u3081\u304b\u3089\u3001\u6e8012\u624d\u306b\u9054\u3057\u305f\u65e5\u306e\u5c5e\u3059\u308b\u5b66\u5e74\u306e\u7d42\u308f\u308a\u307e\u3067\u3001\u5c0f\u5b66\u6821\u306b\u901a\u308f\u305b\u308b\u3088\u3046\u306b\u5b9a\u3081\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u6240\u8b02\u65e9\u751f\u307e\u308c\u6271\u3044\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u516c\u8077\u9078\u6319\u6cd5\u3068\u3082\u77db\u76fe\u304c\u751f\u3058\u3066\u3044\u308b\u3068\u306e\u898b\u89e3\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u79c1\u306f\u300c\u9078\u6319\u306e\u671f\u65e5\u306b\u3088\u308a\u7b97\u5b9a\u3059\u308b\u300d\u3068\u5b9a\u3081\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u671f\u65e5\u3059\u306a\u308f\u3061\u300c\u65e5\u300d\u3092\u542b\u307f\u3001\u5348\u524d0\u6642\u306b\u52b9\u529b\u3092\u6301\u3064\u3082\u306e\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3057\u304b\u3057\u5348\u5f8c12\u6642\u306b\u9078\u6319\u6a29\u3084\u88ab\u9078\u6319\u6a29\u3092\u6709\u3059\u308b\u69d8\u306b\u306a\u308a\u3001\u5b9f\u969b\u306b\u6295\u7968\u306b\u884c\u304f\u6642\u306b\u306f\u307e\u306019\u6b73\u3067\u3042\u308b\u3068\u3044\u3046\u554f\u984c\u304c\u56fd\u4f1a\u306b\u63d0\u8d77\u3055\u308c\u305f\u4e8b\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f55\u3082\u8003\u3048\u305a\u306b\u8a95\u751f\u65e5\u304b\u3089\u5e74\u9f62\u8a08\u7b97\u3092\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u3059\u3002 \u3057\u304b\u3057\u4f55\u3082\u8003\u3048\u306a\u3044\u3068\u8a34\u8a1f\u554f\u984c\u306b\u767a\u5c55\u3059\u308b\u306e\u304c\u5e74\u9f62\u8a08\u7b97\u3067\u3082\u3042\u308a\u307e\u3059\u3002 PHP\u306a\u3089 int(([\u57fa\u6e96\u65e5]-[\u751f\u5e74\u6708\u65e5])\/10000) \u3084 floor(([\u57fa\u6e96\u65e5]-[\u751f\u5e74\u6708 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":715,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[69,18,65],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/703"}],"collection":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=703"}],"version-history":[{"count":13,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions"}],"predecessor-version":[{"id":1067,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions\/1067"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/media\/715"}],"wp:attachment":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}