virtuexru Posted April 18, 2007 Share Posted April 18, 2007 OK, so into my database, one table goes in DATETIME with default format being: 0000-00-00 00:00:00. When I output, how can I convert this to something like - 06/12/99 @ 12:00PM or even - June 21st, 1987 @ 12:00PM ?? Link to comment https://forums.phpfreaks.com/topic/47555-datetime-output-help/ Share on other sites More sharing options...
trq Posted April 18, 2007 Share Posted April 18, 2007 Take a look at the date and related functions / examples. Link to comment https://forums.phpfreaks.com/topic/47555-datetime-output-help/#findComment-232108 Share on other sites More sharing options...
obsidian Posted April 18, 2007 Share Posted April 18, 2007 First option: use the MySQL DATE_FORMAT() function. Second option: use PHP <?php $ts = '2007-02-14 12:00:00'; echo date('F js, Y @ g:ia', strtotime($ts)); ?> Good luck. Link to comment https://forums.phpfreaks.com/topic/47555-datetime-output-help/#findComment-232111 Share on other sites More sharing options...
Glyde Posted April 18, 2007 Share Posted April 18, 2007 Combination of strtotime() with date(). But if the field is DATETIME you should be able to use MySQL to format the date for you. Link to comment https://forums.phpfreaks.com/topic/47555-datetime-output-help/#findComment-232112 Share on other sites More sharing options...
clown[NOR] Posted April 18, 2007 Share Posted April 18, 2007 this is how I've done it: <?php function formatDate($date) { $date = explode("-", $date); $date = date("d. F, Y", mktime(0, 0, 0, $date[1], $date[2], $date[0])); $enMonthArray = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $noMonthArray = array('Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember'); return str_replace($enMonthArray, $noMonthArray, $date); } function formatTime($time) { $time = explode(":", $time); return $time[0].":".$time[1]; } ?> Link to comment https://forums.phpfreaks.com/topic/47555-datetime-output-help/#findComment-232116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.