0

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>

3 Answers 3

1

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');
?>
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

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>

1 Comment

Could you edit your answer to include an explanation of what this does and how it solves the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.