Thiha Han
Thiha Han

Reputation: 1

Cakephp Date format output

I'm trying to display the date in DMY format and database is stored as YMD format. how can I change into DMY format? If I've to use form helper how to I exactly use to display? This is my code for display.

    <?php
$i = 0;
foreach ($jobtasks as $jobtask):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
?>
    <table><tr>
    <td><?php echo $jobtask['Jobtask']['date']; ?>&nbsp;</td>
   </tr>

Upvotes: 0

Views: 1531

Answers (3)

Pruthviraj Chudasama
Pruthviraj Chudasama

Reputation: 448

try this code its work for you....it's store date field time in format DMY that you need...

<td><?php echo date('D M Y', strtotime($jobtask['Jobtask']['date'])); ?>&nbsp;</td>

Upvotes: 0

valentinarho
valentinarho

Reputation: 121

You can use the Time class:

At the beginning of your php file write:

use Cake\I18n\Time; 

And when you want to print the date:

<?php 
   $time = new Time($jobtask['Jobtask']['date']); 
   echo $time->format('dd-MM-yyyy HH:mm:ss');
?>

Upvotes: 1

mark
mark

Reputation: 21743

you should be able to use the time helper: http://book.cakephp.org/view/1471/Formatting

nice(), niceShort() or just format()

Upvotes: 0

Related Questions