{"id":2816,"date":"2019-11-26T13:19:47","date_gmt":"2019-11-26T21:19:47","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2816"},"modified":"2019-11-26T13:19:47","modified_gmt":"2019-11-26T21:19:47","slug":"mysql-datetime","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2816","title":{"rendered":"MySQL Datetime"},"content":{"rendered":"<p>I get temperature data from sensors that report midnight as 00:00:00. I also get data from the State of California CIMIS system and they report midnight as 24:00:00. If I want to merge my data with the state data it doesn\u2019t work. Plus datetime in MySQL isn\u2019t happy about time being 24:00:00.<\/p>\n<p>So to get around that I put the data into my tables with the time portion of the datetime field as 23:59:59. I use BBEdit to edit the raw CSV data so that it can be used in a MySql INSERT statement and it\u2019s just one more <em>find and replace<\/em> to make it work.<\/p>\n<p>For most purposes that is fine, but there are some calculations that I do on an hourly basis and the last reading of the day is yesterday in the CIMIS data compared to my sensors so I get some slightly different answers. Also, if I am missing data for my sensors, it is difficult to add the missing data.<\/p>\n<p>The solution is obvious, just add a second to the CIMIS data. I couldn\u2019t figure out a way to do that in BBEdit or in LibreOffice.<\/p>\n<p>But after the CIMIS data is in the table you can convert dates with 23:59:59 by adding one second to them with a simple MySQL command.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\nUPDATE `values_Temperature_1` SET `datetime_temp` = ADDTIME(`datetime`, &#039;0:0:01&#039;) WHERE SECOND(`datetime`) = &#039;59&#039;\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I get temperature data from sensors that report midnight as 00:00:00. I also get data from the State of California CIMIS system and they report midnight as 24:00:00. If I want to merge my data with the state data it doesn\u2019t work. Plus datetime in MySQL isn\u2019t happy about time being 24:00:00. So to get &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2816\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">MySQL Datetime<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-2816","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2816"}],"version-history":[{"count":4,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2816\/revisions"}],"predecessor-version":[{"id":2820,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2816\/revisions\/2820"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}