Buy Now
Sign in

Format database date-time CCV6

asdtemeraritivoli , February 15 2017
Answered
A
asdtemeraritivoli
Hi,
I would format date-time extract from a db table, from yyyy-mm-dd to dd-mm-yyyy. I test using "Modify Data" function with the following parameters:

Name: modify_data
Data Provider: {data:read_dbTable}
Var Name: {Model.TableField}
Data override: return date("d/m/Y");

the parameters "Select type" of read_dbTable function are is "All matching records."

I call also the function in the event "index" but the date format is not modified.

Could you help me please?

Francesco
admin
Hi Francesco,

The modify data function can not help here, you need a php function.

The syntax depends on where the php function is called and from where do you get the date value.

For example, if you are listing the data inside a table, then the php function should be called inside the "Columns views" of your table like this:
{fn:php_fn_name}


And the php function content should be:

echo date("d/m/Y", strtotime($this->get("table_view_name.row.Model.field")));


Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
A
asdtemeraritivoli
Thanks Max,

This work perfectly with a list in a table but in a "Details List" I tried to insert in the "Filed View":
{fn:php_fn_name}


and the php function:
echo date("d/m/Y", strtotime($this->get("table_view_name.Model.field")))


and also
echo date("d/m/Y", strtotime($this->get("Model.field")))


but the doesn't work, any suggestion about the php function for a "Details List"

Thanks again
Francesco
admin
Hi Francesco,

In a details view its easier, you can call the value from the data read var directly like this:
echo date("d/m/Y", strtotime($this->get("read_data_fn_name.Model.field")))

or
echo date("d/m/Y", strtotime($this->get("details_view_name.row.field")))


Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
A
asdtemeraritivoli
Hi Max,
These codes don't work for me. I tested both.... Here the screenshot of the details view. where is the error?

Thanks again
Francesco
Attachments
Schermata_2017-02-16_alle_13.34.50.png
Schermata_2017-02-16_alle_13.34.50.png
(59.25 KiB)
271 Downloads/Views
admin
Hi Francesco,

The PHP code in the php function is what should be changed, and you should call the php function in the details view, you can not run php code in the details view as you have now.

So you may need this line in the details view:
Gara.data_gara:{fn:php_fn_name}

And the line I sent before in the php function.

Please let me know if you still can't get this done.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
H
healyhatman
Hooray just did this in a faster / easier way.
Let's say your model is called Model.
Let's say your date field is called created, and your table view has a column in the column list called "Model.created:Created"
Let's say your table view is called table1.
In your table view, under Columns views, just put in
Model.created:{date:d-m-Y$(var:table1.row.Model.created)}
replacing d-m-Y with whatever format string you needed.
Web developer at SkySpider.com.au