Jump to content

Recommended Posts

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

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.

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

<?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.

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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.