geko21 Posted June 9, 2011 Share Posted June 9, 2011 hi guys, Im building a really basic blog which is going to be updated from phpmyadmin (until I build a CMS) but I need some help in two areas: Number 1 For the look of the blog I want the date of the post that I entered in phpmyadmin to be shown on the page but instead of the date looking like this 17/01/2011 I need the numbers to be stacked ontop of each and only showing the two numbers of each part other like this 17 01 11 Problem Number 2 is: I have a description for each post but I dont want the whole description to be shown so I need to limit the amount of words the posts are displaying, if that makes sense? Could someone show me how that would be done aswell? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/ Share on other sites More sharing options...
JonnoTheDev Posted June 9, 2011 Share Posted June 9, 2011 1 <?php $date = '17/01/2011'; $date = implode('<br />', explode('/',$date)); echo $date; /* or */ $date = '17/01/2011'; $date = date('d<br />m<br />y', strtotime($date)); echo $date; ?> 2 <?php $sometext = 'Hello my name is Neil'; $chars = 16; $subtext = substr($sometext, 0, $chars); echo $subtext.'.....'; ?> These are really common and simple php functions. I would recommend a basic reference book to assist you with anything small like the above that you need to do. Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227641 Share on other sites More sharing options...
geko21 Posted June 9, 2011 Author Share Posted June 9, 2011 this was a post I did by mistake ---- please read bellow Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227695 Share on other sites More sharing options...
geko21 Posted June 9, 2011 Author Share Posted June 9, 2011 hi mate thanks for the help on the first problem this is what I have done $date = $row->date_post; $date = date('d<br />m<br />y', strtotime($date)); echo $date; my table row with the dates in is called date_post so does this function look right becuase my result is looking like this "170211" but I need it to be 17 01 11 Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227699 Share on other sites More sharing options...
JonnoTheDev Posted June 9, 2011 Share Posted June 9, 2011 <?php $date = date('d-m-y', strtotime($row->date_post)); $date = implode('<br />', explode('-',$date)); echo $date; ?> Dates in a mysql table should be stored in DATE type and not as strings in a VARCHAR. A proper date format is YYYY-MM-DD. You can then convert to UK format using PHP. PHP's date & time functions can become confused when using UK date format. Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227702 Share on other sites More sharing options...
geko21 Posted June 9, 2011 Author Share Posted June 9, 2011 ah cheers buddy seems to be working a treat! Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227707 Share on other sites More sharing options...
xyph Posted June 9, 2011 Share Posted June 9, 2011 AVOID USING PHP'S DATE FUNCTION IF YOU CAN! Use MySQL to solve this http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format SELECT DATE_FORMAT( `date_post`, '%d<br>%m<br>%y' ) as `date_formatted` FROM `table` Then use $row->date_formatted If you prefer neil.johnson's method, you can save a couple explode and implode calls by using <?php $date = date('d<br>m<br>y', strtotime($row->date_post)); echo $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/238909-i-need-some-help-formating-dates-and-limiting-words/#findComment-1227738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.