{"id":2884,"date":"2018-07-05T15:35:15","date_gmt":"2018-07-05T22:35:15","guid":{"rendered":"https:\/\/database.guide\/?p=2884"},"modified":"2021-01-28T14:10:35","modified_gmt":"2021-01-28T04:10:35","slug":"utc_date-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/utc_date-examples-mysql\/","title":{"rendered":"UTC_DATE Examples &#8211; MySQL"},"content":{"rendered":"<p>In <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a>, you can use the <code>UTC_DATE<\/code> function to return the UTC date. UTC stands for Coordinated Universal Time and it&#8217;s the primary time standard by which the world regulates clocks and time.<\/p>\n<p>The result is returned either in <em>&#8216;YYYY-MM-DD&#8217;<\/em> or <em>YYYYMMDD<\/em> format, depending on whether the function is used in a string or numeric context.<\/p>\n<p><!--more--><\/p>\n<h2>Syntax<\/h2>\n<p>You can use either of the following two forms:<\/p>\n<pre>UTC_DATE\r\nUTC_DATE()\r\n<\/pre>\n<p>So no arguments are required.<\/p>\n<h2>Example 1 &#8211; Basic Usage<\/h2>\n<p>Here&#8217;s an example to demonstrate.<\/p>\n<pre>SELECT UTC_DATE;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+\r\n| UTC_DATE   |\r\n+------------+\r\n| 2018-07-05 |\r\n+------------+\r\n<\/pre>\n<h2>Example 2 &#8211; With Parentheses<\/h2>\n<p>In this example I add the parentheses (of course, this makes no difference to the outcome).<\/p>\n<pre>SELECT UTC_DATE();\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+\r\n| UTC_DATE() |\r\n+------------+\r\n| 2018-07-05 |\r\n+------------+\r\n<\/pre>\n<h2>Example 3 &#8211; Numerical Context<\/h2>\n<p>The previous examples were all returned in <em>&#8216;YYYY-MM-DD&#8217;<\/em> format. This is because they were used in a string context.<\/p>\n<p>In this example I use the function in a numerical context. I do this by adding a number to the function.<\/p>\n<pre>SELECT UTC_DATE() + 0;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+\r\n| UTC_DATE() + 0 |\r\n+----------------+\r\n|       20180705 |\r\n+----------------+\r\n<\/pre>\n<p>In this case I added zero, which kept the date the same. However, the result is\u00a0now in\u00a0<em>YYYYMMDD<\/em> format.<\/p>\n<p>There&#8217;s nothing to stop you from adding another number. Example:<\/p>\n<pre>SELECT UTC_DATE() + 5;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+\r\n| UTC_DATE() + 5 |\r\n+----------------+\r\n|       20180710 |\r\n+----------------+\r\n<\/pre>\n<p>Also see <a href=\"https:\/\/database.guide\/utc_time-examples-mysql\/\"><code>UTC_TIME<\/code> Examples<\/a> for returning the UTC time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, you can use the UTC_DATE function to return the UTC date. UTC stands for Coordinated Universal Time and it&#8217;s the primary time standard by which the world regulates clocks and time. The result is returned either in &#8216;YYYY-MM-DD&#8217; or YYYYMMDD format, depending on whether the function is used in a string or numeric &#8230; <a title=\"UTC_DATE Examples &#8211; MySQL\" class=\"read-more\" href=\"https:\/\/database.guide\/utc_date-examples-mysql\/\" aria-label=\"Read more about UTC_DATE Examples &#8211; MySQL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[68,115,93],"class_list":["post-2884","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-date-functions","tag-dates","tag-functions"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=2884"}],"version-history":[{"count":3,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2884\/revisions"}],"predecessor-version":[{"id":2889,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2884\/revisions\/2889"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}