 {"id":58,"date":"2007-10-01T15:00:59","date_gmt":"2007-10-01T20:00:59","guid":{"rendered":"http:\/\/www.networkjack.info\/blog\/2007\/10\/01\/convert-from-us-short-date-to-sql-date-using-mysql-parsing\/"},"modified":"2007-10-01T15:00:59","modified_gmt":"2007-10-01T20:00:59","slug":"convert-from-us-short-date-to-sql-date-using-mysql-parsing","status":"publish","type":"post","link":"http:\/\/www.networkjack.info\/blog\/2007\/10\/01\/convert-from-us-short-date-to-sql-date-using-mysql-parsing\/","title":{"rendered":"Convert from US Short Date to SQL date using MySQL parsing"},"content":{"rendered":"<p>I had a customer submit a batch file to be processed in one of our systems and they handed me an Excel file with short dates (mm\/dd\/yy). Sheesh, this is 2007, can we not get full 4 digit years, please!<\/p>\n<p>so, I wanted to work out a method for quickly converting those date strings within mysql<\/p>\n<p>assume a table of:<\/p>\n<ul>\n<li>BirthDate char(16)<\/li>\n<li>BDMonth tinyint<\/li>\n<li>BDDay tinyint<\/li>\n<li>BDYear smallint<\/li>\n<\/ul>\n<p>UPDATE MyDatesTable<br \/>\nBDMonth = SUBSTRING_INDEX(BirthDate, &#8216;\/&#8217;, 1),<br \/>\nBDDay = SUBSTRING_INDEX( SUBSTRING_INDEX(BirthDate, &#8216;\/&#8217;, 2 ) , &#8216;\/&#8217;, -1 ),<br \/>\nBDYear = SUBSTRING_INDEX(BirthDate, &#8216;\/&#8217;, -1)+1900,<\/p>\n<p>UPDATE MyDatesTable<br \/>\nSET BirthDate = CONCAT(BDYear, &#8216;-&#8216;, BDMonth, &#8216;-&#8216;, BDDay)<\/p>\n<p>ALTER TABLE\u00c2\u00a0 MyDatesTable MyDatesTable MyDatesTable datetime;<\/p>\n<p>2 digits years are SOOO last century&#8230; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a customer submit a batch file to be processed in one of our systems and they handed me an Excel file with short&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.networkjack.info\/blog\/2007\/10\/01\/convert-from-us-short-date-to-sql-date-using-mysql-parsing\/\">Continue reading<span class=\"screen-reader-text\">Convert from US Short Date to SQL date using MySQL parsing<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,12,20,21],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-data-translation","category-database","category-mysql","category-text-munging","entry"],"_links":{"self":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/58"}],"collection":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":0,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}