{"id":1441,"date":"2017-03-21T17:09:45","date_gmt":"2017-03-21T11:39:45","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=1441"},"modified":"2017-03-29T11:02:16","modified_gmt":"2017-03-29T05:32:16","slug":"convert-mysql-datetime-another-format-php","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/convert-mysql-datetime-another-format-php\/","title":{"rendered":"PHP &#8211; Convert from MySQL datetime to another format with PHP"},"content":{"rendered":"<p>Date is important aspect in developing applications such as storing user registration date time ,last login time, date of birth etc.<\/p>\n<p>Mysql has standard format that is YYYY-mm-dd and but we want that to be in regional or in some other format.<\/p>\n<h4 id=\"using-strtotime-and-date-function-printing-only-date\"><span style=\"color: #ff6600;\"><strong>using strtotime and date function printing only date<\/strong><\/span><\/h4>\n[pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%20%0A%24mysqlDateTime%20%3D%20\u20192016-10-17%2021%3A46%3A59\u2019%3B%0Aecho%20date(%22m%2Fd%2FY%22%2C%20strtotime(%24mysqlDateTime))%3B%0Aecho%20%22%3Cbr%3E%22%3B%0A%20%0A%3F%3E%0A\u201d message=\u201dPhp Code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"using-strtotime-and-date-function-printing-in-the-form-of-timestamp\"><span style=\"color: #800080;\"><strong>using strtotime and date function printing in the form of timestamp<\/strong><\/span><\/h4>\n[pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%0A%24old_date%20%3D%20date(\u2018l%2C%20F%20d%20y%20h%3Ai%3As\u2019)%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20returns%20Saturday%2C%20January%2030%2010%2002%3A06%3A34%0A%24old_date_timestamp%20%3D%20strtotime(%24old_date)%3B%0A%24new_date%20%3D%20date(\u2018Y-m-d%20H%3Ai%3As\u2019%2C%20%24old_date_timestamp)%3B%0Aecho%20%24new_date%3B%0Aecho%20%22%3Cbr%3E%22%3B%0A%0A%3F%3E%0A\u201d message=\u201dPhp Code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h4 id=\"strtotime-and-date-printing-only-date-in-text-format\"><span style=\"color: #808000;\"><strong>strtotime and date printing only date in text format<\/strong><\/span><\/h4>\n[pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%0A%24mysqlDateTime%20%3D%20\u20192016-10-17%2021%3A46%3A59\u2019%3B%0A%24date%20%3D%20strtotime(%24mysqlDateTime)%3B%0Aecho%20date(%22j%20F%20Y%22%2C%20%24date)%3B%20%2F%2Foutput%20will%20be%2010%20July%202013%0A%0A%3F%3E%0A\u201d message=\u201dPhp Code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"using-datetime-object-in-php-and-format-function\"><span style=\"color: #ff6600;\"><strong>Using DateTime object in php and format function<\/strong><\/span><\/h4>\n[pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%0A%24old_date%20%3D%20date(\u2018l%2C%20F%20d%20y%20h%3Ai%3As\u2019)%3B%0A%24date%20%3D%20new%20DateTime(%24old_date)%3B%0Aecho%20%24date-%3Eformat(\u2018Y-m-d%20H%3Ai%3As\u2019)%3B%0A%0A%3F%3E%0A\u201d message=\u201dPhp Code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"using-date_create-and-date_format-format-function\"><span style=\"color: #800080;\"><strong>Using date_create and date_format format function<\/strong><\/span><\/h4>\n[pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%0A%24old_date%20%3D%20date(\u2018l%2C%20F%20d%20y%20h%3Ai%3As\u2019)%3B%0A%24date%20%3D%20date_create(%24old_date)%3B%0Aecho%20date_format(%24date%2C%20\u2019Y-m-d%20H%3Ai%3As\u2019)%3B%0Aecho%20%22%3Cbr%3E%22%3B%0A\u201d message=\u201dPhp Code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n","protected":false},"excerpt":{"rendered":"<p>Date is important aspect in developing applications such as storing user registration date time ,last login time, date of birth etc. Mysql has standard format that is YYYY-mm-dd and but we want that to be in regional or in some other format. using strtotime and date function printing only date [pastacode lang=\u201dphp\u201d manual=\u201d%3C%3Fphp%0A%20%0A%24mysqlDateTime%20%3D%20\u20192016-10-17%2021%3A46%3A59\u2019%3B%0Aecho%20date(%22m%2Fd%2FY%22%2C%20strtotime(%24mysqlDateTime))%3B%0Aecho%20%22%3Cbr%3E%22%3B%0A%20%0A%3F%3E%0A\u201d message=\u201dPhp Code\u201d [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,25],"tags":[2817,2816,2815,2821,2822,2818,2820,2819,2814,2823],"class_list":["post-1441","post","type-post","status-publish","format-standard","hentry","category-mysql","category-php","tag-convert-date-to-datetime-in-php-and-mysql","tag-convert-datetime-to-string-php","tag-convert-mysql-datetime-stamp-into-javascripts-date-format","tag-convert-unusual-php-date-format-from-varchar-to-datetime-in-mysql","tag-converting-a-stored-mysql-datetime-from-utc-to-local-offset-in-php","tag-converting-datetime-in-mysql-with-php","tag-converting-mysql-datetime-to-very-specific-format-for-export","tag-datetime-format-php-and-mysql","tag-how-do-you-set-a-default-value-for-a-mysql-datetime-column","tag-php-convert-epoch-to-mysql-datetime-format"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=1441"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1441\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=1441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=1441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=1441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}