Welcome Guest, Not a member yet? Register   Sign In
Formatting a date in a view.
#1

[eluser]gscodeignitor_india[/eluser]
I am absolutely new to Codeignitor and trying to learn some basic skills.

I could do a few things like displaying data stored in MySql etc.

However I could not format the date. ( I need to format the default date to dd-mm-yyyy format )

Please help...

Following is my customer_view file.

<html>


<body>

<table border="3">
<tr>
<th>Customer</th>
<th>P.O. Number</th>
<th>PODate</th>
<th>Config</th>
<th>Qty</th>
<th>Order Value</th>
<th>OA Number</th>
<th>Warranty</th>

</tr>
&lt;?php

foreach($records as $orderdata){
echo "<tr>";

echo "<td>". $orderdata->customer."</td>";
echo "<td>". $orderdata->ponumber."</td>";
echo "<td>". $orderdata->podate. "</td>";
echo "<td>". $orderdata->config ."</td>";
echo "<td>". $orderdata->qty ."</td>";
echo "<td>". $orderdata->ordervalue ."</td>";
echo "<td>". $orderdata->oanumberdate."</td>";
echo "<td>". $orderdata->warranty ."</td>";
echo "</tr>";
}

?&gt;
</table>
&lt;/body&gt;
&lt;/html&gt;

The output I am getting as follows.

The date output for datefield ( in my case it is 'podate' ) is in Year-Month-Date-time format where as I need to display date in Date-Month-Year Format.


Any help is appreciated.

Thanks in advance.
#2

[eluser]PravinS[/eluser]
you can use DATE_FORMAT function of mysql

check: http://dev.mysql.com/doc/refman/5.5/en/d...ate-format
#3

[eluser]gscodeignitor_india[/eluser]
I have tried that as well.

example

echo "<td>". $orderdata->date_format(podate, '%d %m,%Y'). "</td>";
&
echo "<td>". date_format($orderdata->podate, '%d %m,%Y'). "</td>";

But does not help...

Rather page returns with error.

Please help.
#4

[eluser]PravinS[/eluser]
you need to use DATE_FORMAT function of mysql in you MySQL query, not in view file

but if you want to use in your view then you need to use date() function of php, for that you have to convert your "podate" value in timestamp format and use the date function

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

[eluser]Pert[/eluser]
Code:
&lt;?= date('%d %m,%Y', strtotime($orderdata->podate)) ?&gt;
#6

[eluser]gscodeignitor_india[/eluser]
Thanks Pert ....

This line has made the trick...

echo "<td>". date('d/M/Y', strtotime($orderdata->podate)) ."</td>";Thanks ..

Many thanks again.

Regards,




Theme © iAndrew 2016 - Forum software by © MyBB