{"id":6336,"date":"2024-11-14T08:34:29","date_gmt":"2024-11-14T00:34:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6336\/"},"modified":"2024-11-14T08:34:29","modified_gmt":"2024-11-14T00:34:29","slug":"mysql%e6%9f%a5%e8%af%a2%e7%8e%b0%e5%9c%a8%e7%9a%84%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6336\/","title":{"rendered":"mysql\u67e5\u8be2\u73b0\u5728\u7684\u65f6\u95f4"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u67e5\u8be2\u5f53\u524d\u65f6\u95f4\u7684\u516d\u79cd\u65b9\u6cd5\uff1anow() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u548c\u65e5\u671f\u3002current_timestamp \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u6233\uff0c\u5305\u62ec\u5fae\u79d2\u90e8\u5206\u3002get_date() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u3002curdate() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65e5\u671f\uff0c\u683c\u5f0f\u4e3a yyyy-mm-dd\u3002curtime() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u3002localtime() \u51fd\u6570\uff0c\u8fd4\u56de\u672c\u5730\u65f6\u95f4\uff0c\u53d7\u65f6\u533a\u8bbe\u7f6e\u5f71\u54cd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202407\/31\/2024073122554870892.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u73b0\u5728\u7684\u65f6\u95f4\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u73b0\u5728\u7684\u65f6\u95f4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u8be2\u5f53\u524d\u65f6\u95f4<\/strong><\/p>\n<p>MySQL \u4e2d\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u67e5\u8be2\u5f53\u524d\u65f6\u95f4\uff1a<\/p>\n<p><strong>1. NOW() \u51fd\u6570<\/strong><\/p>\n<p>NOW() \u51fd\u6570\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u548c\u65e5\u671f\u3002<\/p>\n<pre>SELECT NOW();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>2023-03-08 14:35:12<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. CURRENT_TIMESTAMP \u51fd\u6570<\/strong><\/p>\n<p>CURRENT_TIMESTAMP \u51fd\u6570\u7c7b\u4f3c\u4e8e NOW(), \u4f46\u5b83\u8fd8\u8fd4\u56de\u5fae\u79d2\u90e8\u5206\u3002<\/p>\n<pre>SELECT CURRENT_TIMESTAMP;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>2023-03-08 14:35:12.567890<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. GET_DATE() \u51fd\u6570<\/strong><\/p>\n<p>GET_DATE() \u51fd\u6570\u53ea\u8fd4\u56de\u5f53\u524d\u65e5\u671f\uff0c\u4e0d\u5305\u542b\u65f6\u95f4\u90e8\u5206\u3002<\/p>\n<pre>SELECT GET_DATE();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>2023-03-08<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. CURDATE() \u51fd\u6570<\/strong><\/p>\n<p>CURDATE() \u51fd\u6570\u4e0e GET_DATE() \u76f8\u4f3c\uff0c\u4f46\u5b83\u4ee5 YYYY-MM-DD \u683c\u5f0f\u8fd4\u56de\u65e5\u671f\u3002<\/p>\n<pre>SELECT CURDATE();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>2023-03-08<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. CURTIME() \u51fd\u6570<\/strong><\/p>\n<p>CURTIME() \u51fd\u6570\u53ea\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\uff0c\u4e0d\u5305\u542b\u65e5\u671f\u90e8\u5206\u3002<\/p>\n<pre>SELECT CURTIME();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>14:35:12<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. LOCALTIME() \u51fd\u6570<\/strong><\/p>\n<p>LOCALTIME() \u51fd\u6570\u8fd4\u56de\u672c\u5730\u65f6\u95f4\uff0c\u53d7\u65f6\u533a\u8bbe\u7f6e\u5f71\u54cd\u3002<\/p>\n<pre>SELECT LOCALTIME();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n<pre>14:35:12<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u73b0\u5728\u7684\u65f6\u95f4\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>\u5728 mysql \u4e2d\u67e5\u8be2\u5f53\u524d\u65f6\u95f4\u7684\u516d\u79cd\u65b9\u6cd5\uff1anow() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u548c\u65e5\u671f\u3002current_timestamp \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u6233\uff0c\u5305\u62ec\u5fae\u79d2\u90e8\u5206\u3002get_date() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u3002curdate() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65e5\u671f\uff0c\u683c\u5f0f\u4e3a yyyy-mm-dd\u3002curtime() \u51fd\u6570\uff0c\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u3002localtime() \u51fd\u6570\uff0c\u8fd4\u56de\u672c\u5730\u65f6\u95f4\uff0c\u53d7\u65f6\u533a\u8bbe\u7f6e\u5f71\u54cd\u3002 \u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u8be2\u5f53\u524d\u65f6\u95f4 MySQL \u4e2d\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u67e5\u8be2\u5f53\u524d\u65f6\u95f4\uff1a 1. NOW() \u51fd\u6570 NOW() \u51fd\u6570\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u548c\u65e5\u671f\u3002 SELECT NOW(); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u793a\u4f8b\uff1a 2023-03-08 14:35:12 \u767b\u5f55\u540e\u590d\u5236 2. CURRENT_TIMESTAMP \u51fd\u6570 CURRENT_TIMESTAMP \u51fd\u6570\u7c7b\u4f3c\u4e8e NOW(), \u4f46\u5b83\u8fd8\u8fd4\u56de\u5fae\u79d2\u90e8\u5206\u3002 SELECT CURRENT_TIMESTAMP; \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u793a\u4f8b\uff1a 2023-03-08 14:35:12.567890 \u767b\u5f55\u540e\u590d\u5236 3. GET_DATE() \u51fd\u6570 GET_DATE() \u51fd\u6570\u53ea\u8fd4\u56de\u5f53\u524d\u65e5\u671f\uff0c\u4e0d\u5305\u542b\u65f6\u95f4\u90e8\u5206\u3002 SELECT GET_DATE(); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u793a\u4f8b\uff1a 2023-03-08 \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 4. CURDATE() [&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-6336","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6336","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=6336"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6336\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}