{"id":5971,"date":"2024-11-14T14:25:32","date_gmt":"2024-11-14T06:25:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5971\/"},"modified":"2024-11-14T14:25:32","modified_gmt":"2024-11-14T06:25:32","slug":"sql-datetime%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5971\/","title":{"rendered":"sql\u00a0datetime\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  datetime \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u9ad8\u7cbe\u5ea6\u7684\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u8303\u56f4\u4e3a 0001-01-01 00:00:00 \u81f3 9999-12-31 23:59:59.9999999\uff0c\u8bed\u6cd5\u4e3a datetime(precision)\uff0c\u5176\u4e2d precision \u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7cbe\u5ea6 (0-7)\uff0c\u9ed8\u8ba4\u4e3a 3\u3002\u5b83\u652f\u6301\u6392\u5e8f\u3001\u8ba1\u7b97\u548c\u65f6\u533a\u8f6c\u6362\u529f\u80fd\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7cbe\u5ea6\u3001\u8303\u56f4\u548c\u65f6\u533a\u8f6c\u6362\u65f6\u7684\u6f5c\u5728\u95ee\u9898\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061203152162921.jpg\" class=\"aligncenter\" title=\"sql\u00a0datetime\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"sql\u00a0datetime\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL DATETIME \u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f DATETIME \u6570\u636e\u7c7b\u578b\uff1f<\/strong><\/p>\n<p>DATETIME \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\u3002\u5b83\u662f\u4e00\u4e2a\u9ad8\u7cbe\u5ea6\u7684\u7c7b\u578b\uff0c\u53ef\u4ee5\u5b58\u50a8\u4ece 0001-01-01 00:00:00 \u5230 9999-12-31 23:59:59.9999999 \u7684\u65e5\u671f\u548c\u65f6\u95f4\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u58f0\u660e DATETIME \u6570\u636e\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>DATETIME(precision)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cprecision \u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7684\u7cbe\u5ea6\uff080-7\uff09\uff0c\u8868\u793a\u6beb\u79d2\u7684\u4f4d\u6570\u3002\u5982\u679c\u7701\u7565 precision\uff0c\u5219\u9ed8\u8ba4\u4e3a 3\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528<\/strong><\/p>\n<p>\u8981\u4f7f\u7528 DATETIME \u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u521b\u5efa\u8868\u65f6\u6307\u5b9a\uff1a<\/strong><\/p>\n<pre>CREATE TABLE my_table (\ndatetime_col DATETIME\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\uff1a<\/strong><\/p>\n<pre>INSERT INTO my_table (datetime_col) VALUES ('2023-03-08 12:34:56');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u529f\u80fd<\/strong><\/p>\n<p>DATETIME \u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ul>\n<li> <strong>\u7cbe\u786e\u5ea6\uff1a<\/strong>\u53ef\u4ee5\u5b58\u50a8\u6beb\u79d2\u7ea7\u7684\u65e5\u671f\u548c\u65f6\u95f4\u503c\u3002<\/li>\n<li> <strong>\u6392\u5e8f\uff1a<\/strong>\u652f\u6301\u57fa\u4e8e\u65e5\u671f\u548c\u65f6\u95f4\u7684\u6392\u5e8f\u3002<\/li>\n<li> <strong>\u8ba1\u7b97\uff1a<\/strong>\u5141\u8bb8\u8fdb\u884c\u65e5\u671f\u548c\u65f6\u95f4\u7684\u7b97\u672f\u8fd0\u7b97\uff0c\u5982\u52a0\u6cd5\u548c\u51cf\u6cd5\u3002<\/li>\n<li> <strong>\u65f6\u533a\u652f\u6301\uff1a<\/strong>\u901a\u8fc7\u4f7f\u7528\u65f6\u533a\u8f6c\u6362\u51fd\u6570\uff0c\u53ef\u4ee5\u5904\u7406\u4e0d\u540c\u65f6\u533a\u7684\u65e5\u671f\u548c\u65f6\u95f4\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<p>\u4f7f\u7528 DATETIME \u6570\u636e\u7c7b\u578b\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li> <strong>\u5c0f\u6570\u70b9\u7cbe\u5ea6\uff1a<\/strong>\u7cbe\u5ea6\u5e94\u6839\u636e\u5b9e\u9645\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e\uff0c\u56e0\u4e3a\u66f4\u9ad8\u7684\u7cbe\u5ea6\u4f1a\u6d88\u8017\u989d\u5916\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<li> <strong>\u8303\u56f4\uff1a<\/strong>\u65e5\u671f\u548c\u65f6\u95f4\u503c\u5fc5\u987b\u5728\u6307\u5b9a\u8303\u56f4\u5185\u3002<\/li>\n<li> <strong>\u65f6\u533a\u8f6c\u6362\uff1a<\/strong>\u65f6\u533a\u8f6c\u6362\u53ef\u80fd\u6d89\u53ca\u6216\u91cd\u590d\uff0c\u56e0\u6b64\u9700\u8981\u8c28\u614e\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql&nbsp;datetime\u600e\u4e48\u7528\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>datetime \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u9ad8\u7cbe\u5ea6\u7684\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u8303\u56f4\u4e3a 0001-01-01 00:00:00 \u81f3 9999-12-31 23:59:59.9999999\uff0c\u8bed\u6cd5\u4e3a datetime(precision)\uff0c\u5176\u4e2d precision \u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7cbe\u5ea6 (0-7)\uff0c\u9ed8\u8ba4\u4e3a 3\u3002\u5b83\u652f\u6301\u6392\u5e8f\u3001\u8ba1\u7b97\u548c\u65f6\u533a\u8f6c\u6362\u529f\u80fd\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7cbe\u5ea6\u3001\u8303\u56f4\u548c\u65f6\u533a\u8f6c\u6362\u65f6\u7684\u6f5c\u5728\u95ee\u9898\u3002 SQL DATETIME \u6570\u636e\u7c7b\u578b \u4ec0\u4e48\u662f DATETIME \u6570\u636e\u7c7b\u578b\uff1f DATETIME \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\u3002\u5b83\u662f\u4e00\u4e2a\u9ad8\u7cbe\u5ea6\u7684\u7c7b\u578b\uff0c\u53ef\u4ee5\u5b58\u50a8\u4ece 0001-01-01 00:00:00 \u5230 9999-12-31 23:59:59.9999999 \u7684\u65e5\u671f\u548c\u65f6\u95f4\u503c\u3002 \u8bed\u6cd5 \u58f0\u660e DATETIME \u6570\u636e\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a DATETIME(precision) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cprecision \u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7684\u7cbe\u5ea6\uff080-7\uff09\uff0c\u8868\u793a\u6beb\u79d2\u7684\u4f4d\u6570\u3002\u5982\u679c\u7701\u7565 precision\uff0c\u5219\u9ed8\u8ba4\u4e3a 3\u3002 \u5982\u4f55\u4f7f\u7528 \u8981\u4f7f\u7528 DATETIME \u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u521b\u5efa\u8868\u65f6\u6307\u5b9a\uff1a CREATE TABLE my_table ( datetime_col DATETIME ); \u767b\u5f55\u540e\u590d\u5236 \u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\uff1a INSERT INTO my_table (datetime_col) VALUES [&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-5971","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5971","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=5971"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5971\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}