{"id":2887,"date":"2018-07-05T15:42:00","date_gmt":"2018-07-05T22:42:00","guid":{"rendered":"https:\/\/database.guide\/?p=2887"},"modified":"2021-01-28T14:10:35","modified_gmt":"2021-01-28T04:10:35","slug":"utc_time-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/utc_time-examples-mysql\/","title":{"rendered":"UTC_TIME Examples &#8211; MySQL"},"content":{"rendered":"<p>In <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a>, you can use the <code>UTC_TIME<\/code> function to return the UTC time. 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;HH:MM:SS&#8217;<\/em> or <em>HHMMSS<\/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_TIME\r\nUTC_TIME([fsp])\r\n<\/pre>\n<p>Where <code>fsp<\/code> is an optional argument that specifies the fractional seconds precision to use in the result.<\/p>\n<h2>Example 1 &#8211; Basic Usage<\/h2>\n<p>Here&#8217;s an example to demonstrate.<\/p>\n<pre>SELECT UTC_TIME;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------+\r\n| UTC_TIME |\r\n+----------+\r\n| 22:38:38 |\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_TIME();\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+\r\n| UTC_TIME() |\r\n+------------+\r\n| 22:38:52   |\r\n+------------+\r\n<\/pre>\n<h2>Example 3 &#8211; Fractional Seconds Precision<\/h2>\n<p>Here I add an argument that specifies the fractional seconds precision to use. In this case I use <code>6<\/code>, which means that the result will have a precision down to the millisecond.<\/p>\n<pre>SELECT UTC_TIME(6);\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+-----------------+\r\n| UTC_TIME(6)     |\r\n+-----------------+\r\n| 22:45:19.912591 |\r\n+-----------------+\r\n<\/pre>\n<p>And in the next example I use <code>3<\/code> to reduce the fractional seconds precision:<\/p>\n<pre>SELECT UTC_TIME(3);\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+--------------+\r\n| UTC_TIME(3)  |\r\n+--------------+\r\n| 22:45:55.415 |\r\n+--------------+\r\n<\/pre>\n<h2>Example 4 &#8211; Numerical Context<\/h2>\n<p>The previous examples were all returned in <em>&#8216;HH:MM:SS&#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_TIME() + 0;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+\r\n| UTC_TIME() + 0 |\r\n+----------------+\r\n|         223914 |\r\n+----------------+\r\n<\/pre>\n<p>In this case I added zero, so the result is\u00a0now in\u00a0<em>HHMMSS<\/em> format.<\/p>\n<p>There&#8217;s nothing to stop you from adding another number. Example:<\/p>\n<pre>SELECT \r\n  UTC_TIME() + 0,\r\n  UTC_TIME() + 5;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+----------------+\r\n| UTC_TIME() + 0 | UTC_TIME() + 5 |\r\n+----------------+----------------+\r\n|         224051 |         224056 |\r\n+----------------+----------------+\r\n<\/pre>\n<p>Also see <a href=\"https:\/\/database.guide\/utc_date-examples-mysql\/\"><code>UTC_DATE<\/code> Examples<\/a> for returning the UTC date.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, you can use the UTC_TIME function to return the UTC time. 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;HH:MM:SS&#8217; or HHMMSS format, depending on whether the function is used in a string or numeric &#8230; <a title=\"UTC_TIME Examples &#8211; MySQL\" class=\"read-more\" href=\"https:\/\/database.guide\/utc_time-examples-mysql\/\" aria-label=\"Read more about UTC_TIME 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-2887","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\/2887","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=2887"}],"version-history":[{"count":3,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2887\/revisions"}],"predecessor-version":[{"id":2891,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2887\/revisions\/2891"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}