views:

38

answers:

4

I'm new to cakephp, I've got a simple Users controller that corresponds to a users table. I have a created field in the table that I want to ouput on the view action using the niceShort() function. how do I use it in the view?

Current code is:

<p>Member since <?php echo $user['User']['created']?></p>

thanks,

Jonesy

+1  A: 

Sorry answer is that in the controller you include the build in time helper:

users_controllee.php:

var $helpers = array('Time');

in the view:

<p>Member since <?php echo $time->niceShort($user['User']['created']); ?></p>
iamjonesy
A: 

Just use built in php function date.

You can use it like this:

< ?php echo date('d.m.Y', strtotime($user['User']['created'])); ?>

You can use any format you like for date formatting based on build in patterns.

http://php.net/manual/en/function.date.php

darko petreski
A: 

Hi,

I think darko is right.

You can simply use PHP function date() to format your date in any type.

Example :

$date = date("Y-m-d H:i:s", strtotime($user['User']['created']));

Here, strtotime() is the function of cakePHP to convert in datetime format.

Now you will have $date variable with a date formatted 'YYYY-mm-dd Hour:Minute:Second'.

For more option you can refer to PHP date manual : http://php.net/manual/en/function.date.php

Hope this will be helpful to you...

Kapil
A: 

Just as point of reference the TimeHelper is CakePHP has a lot of nice stuff worth looking at http://book.cakephp.org/view/1470/Time

Sam D