virtuexru Posted January 21, 2009 Share Posted January 21, 2009 Hey everyone, I just wanted to know what your best approach would be to my problem. I have a date in this format: 1/27/09 I need to be able to convert it into this format: 2009-01-27 Anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/141833-date-conversion-quick-question/ Share on other sites More sharing options...
flyhoney Posted January 21, 2009 Share Posted January 21, 2009 echo date('Y-m-d', strtotime('1/27/09')); Link to comment https://forums.phpfreaks.com/topic/141833-date-conversion-quick-question/#findComment-742594 Share on other sites More sharing options...
tqla Posted February 2, 2009 Share Posted February 2, 2009 I need to do the same thing but this aint working for me. PHP is confusing the month with the date. <?php $mysqlFormat = "12-01-2010"; // Dec 1, 2010 echo date('Y-m-d', strtotime("$mysqlFormat")); ?> This is echoing 2010-01-12 which is wrong! This means Jan 12, 2010. How can I fix this? Link to comment https://forums.phpfreaks.com/topic/141833-date-conversion-quick-question/#findComment-752360 Share on other sites More sharing options...
genericnumber1 Posted February 2, 2009 Share Posted February 2, 2009 <?php $format = explode('/', '1/27/09'); echo date('Y-m-d', mktime(0, 0, 0, $format[0], $format[1], $format[2])); to be sure it knows exactly what the month/day/year is. Link to comment https://forums.phpfreaks.com/topic/141833-date-conversion-quick-question/#findComment-752365 Share on other sites More sharing options...
tqla Posted February 2, 2009 Share Posted February 2, 2009 Ah ha, Thanks genericnumber1! That works. This ain't my ticket so I can't close it. Link to comment https://forums.phpfreaks.com/topic/141833-date-conversion-quick-question/#findComment-752366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.