{"id":2774,"date":"2018-06-27T23:23:18","date_gmt":"2018-06-28T06:23:18","guid":{"rendered":"https:\/\/database.guide\/?p=2774"},"modified":"2021-01-28T14:10:38","modified_gmt":"2021-01-28T04:10:38","slug":"localtime-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/localtime-examples-mysql\/","title":{"rendered":"LOCALTIME Examples &#8211; MySQL"},"content":{"rendered":"<p>The <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a> <code>LOCALTIME<\/code>\u00a0function is a synonym for the <a href=\"https:\/\/database.guide\/now-examples-mysql\/\"><code>NOW()<\/code><\/a> function. It returns the current date and time.<\/p>\n<p>The value is returned\u00a0in <em>&#8216;YYYY-MM-DD HH:MM:SS&#8217;<\/em> or <em>YYYYMMDDHHMMSS<\/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>LOCALTIME\r\nLOCALTIME([fsp])\r\n<\/pre>\n<p>Where the (optional) <code>fsp<\/code> argument specifies the fractional seconds precision for the return value.<\/p>\n<p>If you need to provide the fractional seconds precision, you&#8217;ll need to use the second form.<\/p>\n<h2>Example<\/h2>\n<p>Here&#8217;s an example to demonstrate.<\/p>\n<pre>SELECT LOCALTIME;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+---------------------+\r\n| LOCALTIME           |\r\n+---------------------+\r\n| 2018-06-28 15:22:45 |\r\n+---------------------+\r\n<\/pre>\n<h2>Fractional Seconds Precision<\/h2>\n<p>Here&#8217;s an example of using the <code>fsp<\/code> argument to specify the fractional seconds precision for the return value.<\/p>\n<pre>SELECT LOCALTIME(6);\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------------------+\r\n| LOCALTIME(6)               |\r\n+----------------------------+\r\n| 2018-06-28 15:23:23.380839 |\r\n+----------------------------+\r\n<\/pre>\n<h2>Numeric Context<\/h2>\n<p>Here&#8217;s an example of using the <code>LOCALTIME<\/code> function in a numeric context.<\/p>\n<pre>SELECT LOCALTIME + 0;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+\r\n| LOCALTIME + 0  |\r\n+----------------+\r\n| 20180628152338 |\r\n+----------------+\r\n<\/pre>\n<p>You can also use a nonzero value to add or subtract from the return value. For example:<\/p>\n<pre>SELECT \r\n    LOCALTIME + 0,\r\n    LOCALTIME + 5;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+----------------+\r\n| LOCALTIME + 0  | LOCALTIME + 5  |\r\n+----------------+----------------+\r\n| 20180628152503 | 20180628152508 |\r\n+----------------+----------------+\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The MySQL LOCALTIME\u00a0function is a synonym for the NOW() function. It returns the current date and time. The value is returned\u00a0in &#8216;YYYY-MM-DD HH:MM:SS&#8217; or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.<\/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-2774","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\/2774","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=2774"}],"version-history":[{"count":1,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2774\/revisions"}],"predecessor-version":[{"id":2775,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2774\/revisions\/2775"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}