user3652541
user3652541

Reputation: 83

CAKE PHP change date format

I have the following code which displays all calls details, I want the date format of "call_date" to change to "dd-mm-yyyy" and I have got the following code in my calls/index.ctp:

<div class="callsIndex">
    <h2><?php echo __('Call Details'); ?>   </h2>
    <div class="bottomButtonnew"><?php echo $this->Html->link(__('Add Calls'), array('action' => 'add')); ?></div>


    <table cellpadding="0" cellspacing="0">
        <tr>

            <th><?php echo $this->Paginator->sort('Call Date'); ?></th>
            <th><?php echo $this->Paginator->sort('Call Time'); ?></th>
            <th><?php echo $this->Paginator->sort('Comments'); ?></th>
            <th><?php echo $this->Paginator->sort('Next Call Date'); ?></th>
            <th><?php echo $this->Paginator->sort('Customer Name'); ?></th>
            <th><?php echo $this->Paginator->sort('Company Name'); ?></th>
            <th><?php echo $this->Paginator->sort('Employee Name'); ?></th>
            <th class="actions"><?php echo __(''); ?></th>
        </tr>
        <?php foreach ($calls as $call): ?>
            <tr>

                <td><?php echo h($call['Call']['call_date']); ?>&nbsp;</td>
                <td><?php echo h($call['Call']['call_time']); ?>&nbsp;</td>
                <td><?php echo h($call['Call']['comments']); ?>&nbsp;</td>
                <td><?php echo h($call['Call']['next_call_date']); ?>&nbsp;</td>
                <td>
                    <?php echo $this->Html->link($call['Customers']['customer_name'], array('controller' => 'customers', 'action' => 'view', $call['Customers']['id'])); ?>

                </td>
                <td>
                    <?php echo $this->Html->link($call['Companies']['company_name'], array('controller' => 'companies', 'action' => 'view', $call['Companies']['id'])); ?>
                </td>
                <td>
                    <?php echo $this->Html->link($call['Employees']['employee_name'], array('controller' => 'employees', 'action' => 'view', $call['Employees']['id'])); ?>
                </td>
                <td class="actions">


                    <?php echo $this->Html->link(__('View'), array('action' => 'view', $call['Call']['id'])); ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
    <p>
        <?php
        echo $this->Paginator->counter(array(
            'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total')
        ));
        ?>  </p>
    <div class="paging">
        <?php
        echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('separator' => ''));
        echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
        ?>
    </div>
    <br>

</div>

How can I change the date format in "call_date" to dd-mm-yyyy? can someone help?

Upvotes: 3

Views: 9458

Answers (2)

ndm
ndm

Reputation: 60503

An alternative to using the date() and strtotime() functions (as mentioned previously in the comments and @VishalSharma's answer) would be to use the time helper that ships with CakePHP.

The TimeHelper::format() method can format date/time values using the strftime() formatting options:

$this->Time->format($call['Call']['call_date'], '%d-%m-%Y')

http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html

Upvotes: 6

Vishal Sharma
Vishal Sharma

Reputation: 1372

Use this

 <td><?php echo date("d-m-Y", strtotime($call['Call']['call_date'])); ?>&nbsp;</td>

Upvotes: 8

Related Questions