{"id":5952,"date":"2024-11-14T12:58:53","date_gmt":"2024-11-14T04:58:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5952\/"},"modified":"2024-11-14T12:58:53","modified_gmt":"2024-11-14T04:58:53","slug":"%e5%a6%82%e4%bd%95%e7%94%a8sql%e5%b0%86%e6%97%b6%e9%97%b4%e6%88%b3%e8%bd%ac%e6%8d%a2%e6%97%a5%e6%9c%9f%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5952\/","title":{"rendered":"\u5982\u4f55\u7528sql\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u65e5\u671f\u683c\u5f0f"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5c06 sql \u4e2d\u7684\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528 to_char() \u51fd\u6570\uff1ato_char(timestamp_column, &#8216;yyyy-mm-dd&#8217;) \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u5b57\u7b26\u4e32\u3002\u53ef\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u683c\u5f0f\uff0c\u5982 &#8216;yyyy-mm-dd hh24:mi:ss&#8217;\uff08\u65e5\u671f\u548c\u65f6\u95f4\uff09\u548c &#8216;yyyy-mm-dd hh:mi:ss am&#8217;\uff08\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5e26 am\/pm\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/06\/2024060609181712905.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528sql\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u65e5\u671f\u683c\u5f0f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528sql\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u65e5\u671f\u683c\u5f0f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 SQL \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u683c\u5f0f<\/strong><\/p>\n<p><strong>\u8f6c\u6362\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 TO_CHAR() \u51fd\u6570\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>TO_CHAR(timestamp_column, 'YYYY-MM-DD')<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>timestamp_column\uff1a<\/strong>\u9700\u8981\u8f6c\u6362\u7684\u65f6\u95f4\u6233\u5217\u3002<\/li>\n<li> <strong>&#8216;YYYY-MM-DD&#8217;\uff1a<\/strong>\u6240\u9700\u7684\u65e5\u671f\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT TO_CHAR(timestamp_column, 'YYYY-MM-DD') FROM table_name;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5176\u4ed6\u683c\u5f0f\uff1a<\/strong><\/p>\n<p>\u9664\u4e86 &#8216;YYYY-MM-DD&#8217;\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u683c\u5f0f\uff1a<\/p>\n<ul>\n<li>&#8216;YYYY-MM-DD HH24:MI:SS&#8217;: \u65e5\u671f\u548c\u65f6\u95f4<\/li>\n<li>&#8216;YYYY-MM-DD HH:MI:SS AM&#8217;: \u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26 AM\/PM\uff09<\/li>\n<li>&#8216;YYYY-MM-DD HH:MI:SS PM&#8217;: \u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26 AM\/PM\uff09<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u65f6\u95f4\u6233\u5fc5\u987b\u4ee5 Unix \u65f6\u95f4\u6233\u683c\u5f0f\u5b58\u50a8\u3002<\/li>\n<li>\u5982\u679c\u65f6\u95f4\u6233\u4e0d\u662f Unix \u65f6\u95f4\u6233\uff0c\u9700\u8981\u5148\u5c06\u5176\u8f6c\u6362\u4e3a Unix \u65f6\u95f4\u6233\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7528sql\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u65e5\u671f\u683c\u5f0f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5c06 sql \u4e2d\u7684\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528 to_char() \u51fd\u6570\uff1ato_char(timestamp_column, &#8216;yyyy-mm-dd&#8217;) \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u5b57\u7b26\u4e32\u3002\u53ef\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u683c\u5f0f\uff0c\u5982 &#8216;yyyy-mm-dd hh24:mi:ss&#8217;\uff08\u65e5\u671f\u548c\u65f6\u95f4\uff09\u548c &#8216;yyyy-mm-dd hh:mi:ss am&#8217;\uff08\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5e26 am\/pm\uff09\u3002 \u5982\u4f55\u7528 SQL \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u683c\u5f0f \u8f6c\u6362\u65b9\u6cd5\uff1a \u4f7f\u7528 TO_CHAR() \u51fd\u6570\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\u5b57\u7b26\u4e32\u3002 \u8bed\u6cd5\uff1a TO_CHAR(timestamp_column, &#8216;YYYY-MM-DD&#8217;) \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\uff1a timestamp_column\uff1a\u9700\u8981\u8f6c\u6362\u7684\u65f6\u95f4\u6233\u5217\u3002 &#8216;YYYY-MM-DD&#8217;\uff1a\u6240\u9700\u7684\u65e5\u671f\u683c\u5f0f\u3002 \u793a\u4f8b\uff1a SELECT TO_CHAR(timestamp_column, &#8216;YYYY-MM-DD&#8217;) FROM table_name; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4ed6\u683c\u5f0f\uff1a \u9664\u4e86 &#8216;YYYY-MM-DD&#8217;\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u683c\u5f0f\uff1a &#8216;YYYY-MM-DD HH24:MI:SS&#8217;: \u65e5\u671f\u548c\u65f6\u95f4 &#8216;YYYY-MM-DD HH:MI:SS AM&#8217;: \u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26 AM\/PM\uff09 &#8216;YYYY-MM-DD HH:MI:SS PM&#8217;: \u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26 AM\/PM\uff09 \u6ce8\u610f\uff1a \u65f6\u95f4\u6233\u5fc5\u987b\u4ee5 Unix \u65f6\u95f4\u6233\u683c\u5f0f\u5b58\u50a8\u3002 \u5982\u679c\u65f6\u95f4\u6233\u4e0d\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5952","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5952"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5952\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}