{"id":2981,"date":"2020-07-01T17:03:30","date_gmt":"2020-07-01T16:03:30","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2981"},"modified":"2025-04-10T17:06:58","modified_gmt":"2025-04-10T16:06:58","slug":"datetime-where","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/queries\/select\/datetime-where","title":{"rendered":"DateTime WHERE"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Rows with a DateTime in the past <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$sql1 = \"SELECT * FROM my_table WHERE my_date_field &lt; NOW()\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Time based condition<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Where timestamp is more recent than (Now() - # mins)\n$sql1 = \"SELECT * FROM tblStatus WHERE MyDateTimeColumn &gt; DATE_SUB(now(), INTERVAL 5 MINUTE)\";\n\n\/\/Where timestamp is older than (Now() - # mins)\n$sql1 = \"SELECT * FROM tblStatus WHERE MyDateTimeColumn &lt; DATE_SUB(now(), INTERVAL 5 MINUTE)\";\n\n\/\/Where DateTime is more recent than (Now() + # mins)\n$sql1 = \"SELECT * FROM tblStatus WHERE MyDateTimeColumn &lt; DATE_ADD(now(), INTERVAL 5 MINUTE)\";<\/code><\/pre>\n\n\n\n<p>Argument can be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MICROSECOND<\/li>\n\n\n\n<li>SECOND<\/li>\n\n\n\n<li>MINUTE<\/li>\n\n\n\n<li>HOUR<\/li>\n\n\n\n<li>DAY<\/li>\n\n\n\n<li>WEEK<\/li>\n\n\n\n<li>MONTH<\/li>\n\n\n\n<li>QUARTER<\/li>\n\n\n\n<li>YEAR<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Null or in the future<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  ( MyDateTimeColumn IS NULL OR MyDateTimeColumn > Now() )<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Rows with a DateTime in the past Time based condition Argument can be: Null or in the future<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[257,64,258],"tags":[],"class_list":["post-2981","post","type-post","status-publish","format-standard","hentry","category-datetime","category-select","category-where"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2981"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2981\/revisions"}],"predecessor-version":[{"id":4874,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2981\/revisions\/4874"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}