xiao Posted January 12, 2008 Share Posted January 12, 2008 What I need: - Get the day and month out of a mysql 'date' cell - Transform the month to text - Take the 1st 3 characters from the month name What I have: $date = explode("-", $info['submitdatum']); $day=$date[2]; $month=$date[1]; I'm stuck now Link to comment https://forums.phpfreaks.com/topic/85694-solved-mysql-date-transforming/ Share on other sites More sharing options...
phpSensei Posted January 12, 2008 Share Posted January 12, 2008 <?php $date = explode("-", $info['submitdatum']); $day=$date[2]; $month=$date[1]; $month = substr($month,0,3); ?> RESULTS Oct Also an easier way to do this is by transforming it when you put it in the DB. For example <?php $current = time(); $current = date("Y-m-d",$current); // Do query $month = explode("-",$current); $month = $month[1]; echo $month; // JAN, SEP, ...etc ?> http://ca3.php.net/substr http://ca3.php.net/manual/en/function.date.php Link to comment https://forums.phpfreaks.com/topic/85694-solved-mysql-date-transforming/#findComment-437349 Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2008 Share Posted January 12, 2008 Just do it directly in your mysql SELECT query - SELECT DATE_FORMAT(submitdatum,'%e %b') FROM your_table WHERE your_where_conditions... This returns the day of the month, numeric (0..31) and the abbreviated month name (Jan..Dec) Done! Link to comment https://forums.phpfreaks.com/topic/85694-solved-mysql-date-transforming/#findComment-437370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.