November 25, 201312 yr I've looked on google for this but can't find an answer, only lots of unrelated content. I'm echoing a date from my MySQL database using <?php echo $row_events['fromdate']; ?> which outputs 2013-12-12. but I need to echo only the month from this record. I know I can display the month from the server using <?php echo date("F"); ?> but not sure how to combine the two and display only the month from my database. Thanks
November 25, 201312 yr <?php $parts = explode('-', $row_events['fromdate']); echo $parts[1]; ?> if thats uk format or <?php $parts = explode('-', $row_events['fromdate']); echo $parts[2]; ?> if it is USA format
November 25, 201312 yr Author Awesome, thanks I just discovered substr so managed to get it working using <?php echo substr($row_events['fromdate'],5,2); ?> but your code works great too. Any idea how to get the date to display as the month name? I know it's usually echo date("F") but not sure how to work it into this code. Thanks for you help buddy
November 25, 201312 yr Author Got this working now. I used <?php $eventdate = $row_events['fromdate']; ?> Then to display the month and day: <?php echo date('M', strtotime($eventdate . '-1')); ?> <?php echo date('d', strtotime($eventdate . '-2')); ?> Hope this helps someone else and that its the correct way of doing it as I messed around with the '-1' and '-2' not really knowing what they do, but it works Edited November 25, 201312 yr by drennan
Create an account or sign in to comment