{"id":5302,"date":"2012-04-12T12:06:09","date_gmt":"2012-04-12T06:36:09","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=5302"},"modified":"2012-04-12T12:06:09","modified_gmt":"2012-04-12T06:36:09","slug":"clear-time-function-for-mysql","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/clear-time-function-for-mysql\/","title":{"rendered":"Clear Time function for MySQL"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>Here is a simple function that can allow you to clear time from the DATETIME field of your database table<\/p>\n<p>[sql]<br \/>\nDROP FUNCTION IF EXISTS cleartime;<br \/>\ndelimiter \/\/<br \/>\nCREATE FUNCTION cleartime(dt datetime) RETURNS DATETIME<br \/>\n  NO SQL<br \/>\n  DETERMINISTIC<br \/>\nBEGIN<br \/>\n  DECLARE t    varchar(15);               &#8212; the time part of the dt<br \/>\n  DECLARE rdt  datetime default dt;    \t  &#8212; the datetime after time part is cleared<\/p>\n<p>  SET t = TIME(dt);<br \/>\n  SET rdt = SUBTIME(dt,t);<\/p>\n<p>  RETURN rdt;<br \/>\nEND \/\/<br \/>\ndelimiter ;<br \/>\n[\/sql]<\/p>\n<p>To import this function to your database just copy and paste above code in MySQL command prompt with your database selected.<\/p>\n<p>The implementation is shown in following example:<\/p>\n<p>[sql]<br \/>\nselect cleartime(datetime_field) from table_name;     &#8212; to view field with its time cleared<br \/>\n                     &#8211;OR<br \/>\nupdate table_name set datetime_field=cleartime(datetime_feild) from table_name;<br \/>\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, Here is a simple function that can allow you to clear time from the DATETIME field of your database table [sql] DROP FUNCTION IF EXISTS cleartime; delimiter \/\/ CREATE FUNCTION cleartime(dt datetime) RETURNS DATETIME NO SQL DETERMINISTIC BEGIN DECLARE t varchar(15); &#8212; the time part of the dt DECLARE rdt datetime default dt; [&hellip;]<\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[797,4843,76],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5302"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=5302"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5302\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=5302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=5302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=5302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}