{"id":1195,"date":"2013-03-04T02:28:45","date_gmt":"2013-03-04T08:28:45","guid":{"rendered":"http:\/\/bateru.com\/news\/?p=1195"},"modified":"2018-07-01T23:18:10","modified_gmt":"2018-07-02T05:18:10","slug":"code-of-the-day-javascript-auto-complete-date-format-mmddyyyy","status":"publish","type":"post","link":"https:\/\/bateru.com\/news\/2013\/03\/code-of-the-day-javascript-auto-complete-date-format-mmddyyyy\/","title":{"rendered":"Code of the Day: Javascript Auto-complete date format MMDDYYYY"},"content":{"rendered":"<p><code><\/p>\n<pre lang=\"javascript\">\r\n\/**\r\n* This function helps to autocomplete the date format MMDDYYY\r\n* Converts M to 0M and MMD to MM0D. Ex. `1\/` to `01\/`, `01\/1\/` to `01\/01\/`\r\n* Adds slash for MM and MMDD Ex. `01` to `01\/`, `01\/02` to `01\/02\/`\r\n* Converts YY to YYYY. Ex. `01\/01\/01` to `01\/01\/2001`\r\n*\r\n* @param {String} str\r\n* @return {String}\r\n*\/\r\nvar autocompleteMMDDYYYYDateFormat = function (str) {\r\n        str = str.trim();\r\n        var matches, year,\r\n                looksLike_MM_slash_DD = \/^(\\d\\d\\\/)?\\d\\d$\/,\r\n                looksLike_MM_slash_D_slash = \/^(\\d\\d\\\/)?(\\d\\\/)$\/,\r\n                looksLike_MM_slash_DD_slash_DD = \/^(\\d\\d\\\/\\d\\d\\\/)(\\d\\d)$\/;\r\n\r\n        if( looksLike_MM_slash_DD.test(str) ){\r\n                str += \"\/\";\r\n        }else if( looksLike_MM_slash_D_slash.test(str) ){\r\n                str = str.replace( looksLike_MM_slash_D_slash, \"$10$2\");\r\n        }else if( looksLike_MM_slash_DD_slash_DD.test(str) ){\r\n                matches = str.match( looksLike_MM_slash_DD_slash_DD );\r\n                year = Number( matches[2] ) < 20 ? \"20\" : \"19\";\r\n                str = String( matches[1] ) + year + String(matches[2]);\r\n        }\r\n        return str;\r\n};\r\n<\/pre>\n<p><\/code><\/p>\n<h2>Demo<\/h2>\n<p><iframe style=\"width: 100%; height: 300px\" src=\"\/\/jsfiddle.net\/DQMQw\/111\/embedded\/\" allowfullscreen=\"allowfullscreen\" frameborder=\"0\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * This function helps to autocomplete the date format MMDDYYY * Converts M to 0M and MMD to MM0D. Ex. `1\/` to `01\/`, `01\/1\/` to `01\/01\/` * Adds slash for MM and MMDD Ex. `01` to `01\/`, `01\/02` to `01\/02\/` * Converts YY to YYYY. Ex. `01\/01\/01` to `01\/01\/2001` * * @param {String} str &hellip; <a href=\"https:\/\/bateru.com\/news\/2013\/03\/code-of-the-day-javascript-auto-complete-date-format-mmddyyyy\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Code of the Day: Javascript Auto-complete date format MMDDYYYY<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10],"tags":[30,164,5],"class_list":["post-1195","post","type-post","status-publish","format-standard","hentry","category-frontend-tech","category-tutorials","tag-code-of-the-day","tag-javascript","tag-jquery"],"_links":{"self":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/comments?post=1195"}],"version-history":[{"count":3,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1195\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1195\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/media?parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/categories?post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/tags?post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}