{"id":179852,"date":"2024-11-09T05:20:17","date_gmt":"2024-11-08T21:20:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179852\/"},"modified":"2024-11-09T05:20:17","modified_gmt":"2024-11-08T21:20:17","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%8d%b2%e5%8f%96%e7%95%b6%e5%89%8d%e6%97%a5%e6%9c%9f-%e6%95%b8%e6%93%9a%e5%ba%ab-%e7%8d%b2%e5%8f%96%e7%95%b6%e5%89%8d%e6%97%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179852\/","title":{"rendered":"\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u7576\u524d\u65e5\u671f (\u6578\u64da\u5eab \u7372\u53d6\u7576\u524d\u65e5\u671f)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%8d%b2%e5%8f%96%e7%95%b6%e5%89%8d%e6%97%a5%e6%9c%9f-ioiUToUZlI\">\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u7576\u524d\u65e5\u671f<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7372\u53d6\u7576\u524d\u65e5\u671f\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\uff0c\u7121\u8ad6\u662f\u5728\u6578\u64da\u5206\u6790\u3001\u5831\u544a\u751f\u6210\u9084\u662f\u6578\u64da\u8a18\u9304\u4e2d\u3002\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u65e5\u671f\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5e7e\u7a2e\u4e3b\u6d41\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u7372\u53d6\u7576\u524d\u65e5\u671f\u7684\u65b9\u6cd5\uff0c\u5305\u62ec MySQL\u3001PostgreSQL\u3001SQL Server \u548c Oracle\u3002<\/p>\n<h2 id=\"mysql-ioiUToUZlI\">MySQL<\/h2>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>CURDATE()<\/code> \u6216 <code>NOW()<\/code> \u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u65e5\u671f\u3002\u9019\u5169\u500b\u51fd\u6578\u7684\u4e3b\u8981\u5340\u5225\u5728\u65bc\uff0c<code>CURDATE()<\/code> \u53ea\u8fd4\u56de\u65e5\u671f\u90e8\u5206\uff0c\u800c <code>NOW()<\/code> \u5247\u8fd4\u56de\u65e5\u671f\u548c\u6642\u9593\u3002<\/p>\n<pre><code>SELECT CURDATE();  -- \u7372\u53d6\u7576\u524d\u65e5\u671f\nSELECT NOW();       -- \u7372\u53d6\u7576\u524d\u65e5\u671f\u548c\u6642\u9593\n<\/code><\/pre>\n<h2 id=\"postgresql-ioiUToUZlI\">PostgreSQL<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>CURRENT_DATE<\/code> \u6216 <code>NOW()<\/code> \u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u65e5\u671f\u3002<code>CURRENT_DATE<\/code> \u53ea\u8fd4\u56de\u65e5\u671f\uff0c\u800c <code>NOW()<\/code> \u8fd4\u56de\u65e5\u671f\u548c\u6642\u9593\u3002<\/p>\n<pre><code>SELECT CURRENT_DATE;  -- \u7372\u53d6\u7576\u524d\u65e5\u671f\nSELECT NOW();          -- \u7372\u53d6\u7576\u524d\u65e5\u671f\u548c\u6642\u9593\n<\/code><\/pre>\n<h2 id=\"sql-server-ioiUToUZlI\">SQL Server<\/h2>\n<p>\u5728 SQL Server \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>GETDATE()<\/code> \u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u7684\u65e5\u671f\u548c\u6642\u9593\u3002\u5982\u679c\u53ea\u9700\u8981\u65e5\u671f\u90e8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>CAST<\/code> \u6216 <code>CONVERT<\/code> \u51fd\u6578\u4f86\u8f49\u63db\u3002<\/p>\n<pre><code>SELECT GETDATE();                     -- \u7372\u53d6\u7576\u524d\u65e5\u671f\u548c\u6642\u9593\nSELECT CAST(GETDATE() AS DATE);       -- \u7372\u53d6\u7576\u524d\u65e5\u671f\n<\/code><\/pre>\n<h2 id=\"oracle-ioiUToUZlI\">Oracle<\/h2>\n<p>\u5728 Oracle \u6578\u64da\u5eab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>SYSDATE<\/code> \u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u7684\u65e5\u671f\u548c\u6642\u9593\u3002\u5982\u679c\u9700\u8981\u53ea\u7372\u53d6\u65e5\u671f\u90e8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>TRUNC<\/code> \u51fd\u6578\u3002<\/p>\n<pre><code>SELECT SYSDATE FROM dual;           -- \u7372\u53d6\u7576\u524d\u65e5\u671f\u548c\u6642\u9593\nSELECT TRUNC(SYSDATE) FROM dual;      -- \u7372\u53d6\u7576\u524d\u65e5\u671f\n<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%95%b6%e5%89%8d%e6%97%a5%e6%9c%9f%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-ioiUToUZlI\">\u4f7f\u7528\u7576\u524d\u65e5\u671f\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>\u7372\u53d6\u7576\u524d\u65e5\u671f\u7684\u529f\u80fd\u5728\u8a31\u591a\u61c9\u7528\u5834\u666f\u4e2d\u90fd\u975e\u5e38\u91cd\u8981\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u8a18\u9304\uff1a<\/strong>\u5728\u63d2\u5165\u6578\u64da\u6642\uff0c\u901a\u5e38\u9700\u8981\u8a18\u9304\u7576\u524d\u7684\u65e5\u671f\u548c\u6642\u9593\uff0c\u4ee5\u4fbf\u8ffd\u8e64\u6578\u64da\u7684\u8b8a\u66f4\u3002<\/li>\n<li><strong>\u5831\u544a\u751f\u6210\uff1a<\/strong>\u5728\u751f\u6210\u5831\u544a\u6642\uff0c\u7576\u524d\u65e5\u671f\u53ef\u4ee5\u7528\u65bc\u986f\u793a\u5831\u544a\u7684\u751f\u6210\u6642\u9593\u3002<\/li>\n<li><strong>\u6578\u64da\u5206\u6790\uff1a<\/strong>\u5728\u9032\u884c\u6578\u64da\u5206\u6790\u6642\uff0c\u7576\u524d\u65e5\u671f\u53ef\u4ee5\u7528\u65bc\u7be9\u9078\u6578\u64da\uff0c\u4f8b\u5982\u67e5\u8a62\u6700\u8fd1\u4e00\u5468\u7684\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ioiUToUZlI\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\uff0c\u7372\u53d6\u7576\u524d\u65e5\u671f\u7684\u65b9\u6cd5\u5404\u6709\u4e0d\u540c\uff0c\u4f46\u57fa\u672c\u4e0a\u90fd\u63d0\u4f9b\u4e86\u7c21\u55ae\u6613\u7528\u7684\u51fd\u6578\u4f86\u5be6\u73fe\u9019\u4e00\u529f\u80fd\u3002\u7121\u8ad6\u662f MySQL\u3001PostgreSQL\u3001SQL Server \u9084\u662f Oracle\uff0c\u958b\u767c\u8005\u90fd\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u51fd\u6578\u4f86\u7372\u53d6\u7576\u524d\u65e5\u671f\u3002\u9019\u4e9b\u529f\u80fd\u5728\u6578\u64da\u7ba1\u7406\u548c\u5206\u6790\u4e2d\u626e\u6f14\u8457\u91cd\u8981\u89d2\u8272\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u8655\u7406\u548c\u5229\u7528\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u5176\u4ed6\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u7576\u524d\u65e5\u671f\uff0c\u638c\u63e1\u4f7f\u7528 SQL \u67e5\u8a62\u548c\u51fd\u6578\u4f86\u6709\u6548\u63d0\u53d6\u7576\u524d\u65e5\u671f\u7684\u6280\u5de7\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-179852","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=179852"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179852\/revisions"}],"predecessor-version":[{"id":179853,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179852\/revisions\/179853"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}