honsoworld Posted April 5, 2008 Share Posted April 5, 2008 I am retrieving a date stamp from MySQL that is in the format of yyyy-mm-dd. How do I make PHP manipulate that to display mm/dd/yy. To make it easier, lets just say I have a variable: $mysql_date = "2008-04-05"; How do I get this variable to be: $php_date = "05/04/08"; Link to comment https://forums.phpfreaks.com/topic/99730-solved-mysql-time-manipulation-in-php/ Share on other sites More sharing options...
Barand Posted April 5, 2008 Share Posted April 5, 2008 2 options 1 ) Use Mysql DATE_FORMAT() function in the query 2 ) Format on output using PHP date() function Link to comment https://forums.phpfreaks.com/topic/99730-solved-mysql-time-manipulation-in-php/#findComment-510132 Share on other sites More sharing options...
honsoworld Posted April 5, 2008 Author Share Posted April 5, 2008 Can someone elaborate on using the PHP date() function. That is what I was interested in, but I thought that was just for the current date. How do I uses that with a given datestamp? thanks Link to comment https://forums.phpfreaks.com/topic/99730-solved-mysql-time-manipulation-in-php/#findComment-510134 Share on other sites More sharing options...
tippy_102 Posted April 5, 2008 Share Posted April 5, 2008 function FriendlyDate($SqDate) { list($Year,$Month,$Day) = split('-',$SqDate); //Remove the '-' from the standard MySQL date format //check to see if year is NULL or 0000 if so, lets not print anything if (($Year == "0000") or ($Year == NULL)) { $realDate = ""; } ELSE { $stampeddate = mktime(12,0,0,$Month,$Day,$Year); //Create a UNIX style timestamp from the result $realDate = date("M d, Y",$stampeddate); //Format the UNIX timestamp } $realDate = str_replace (" ", " ", $realDate); return $realDate; } Link to comment https://forums.phpfreaks.com/topic/99730-solved-mysql-time-manipulation-in-php/#findComment-510142 Share on other sites More sharing options...
Barand Posted April 5, 2008 Share Posted April 5, 2008 www.php.net/date <?php <?php $dbdate = '2008-04-03'; echo date ('jS F, Y', strtotime($dbdate)); // 3rd April, 2008 echo date ('m/d/y', strtotime($dbdate)); // 04/03/08 ?> Link to comment https://forums.phpfreaks.com/topic/99730-solved-mysql-time-manipulation-in-php/#findComment-510161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.