How to format datetime retrieved from database using Editor
How to format datetime retrieved from database using Editor
HI Everyone,
I have a field in a table of my datatabase that keeps track of the time the record is saved (it is a timestamp saved in this format: YYYY-MM-DD HH:mm:ss). That field is not in my form.
But I would like to display its values in my table in a specific format (DD-MM-YYYY HH:mm:ss). How can I go about it?
NB: I am using Editor
Thanks for your help.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Using a get formatter (assuming you are using the PHP libraries, docs are available for the .NET and Node libraries as well).
You'd need to include the column as a field in the server-side code, but simply don't include it in the client-side Editor
fieldsarray.Allan
Thanks Allan, it really helped.
Now my issue is that I can only have the date in English format.
How can I have it in French format (DD-MM-YYYY) ?
Thanks
A get formatter should be able to show that format. Could you show me the formatter you are using please?
Allan
This is what I'm currently using
**Field::inst( 'student.date_updated' )->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_850 )**This one gives me this results : 2018-01-24 09:51:54
But the desired result is 24-01-2018 09:51:54
When I tried this, it doesn't work,
_**Field::inst( 'student.date_updated' )->getFormatter( Format::date_sql_to_format( 'd-m-Y' ) )**_Kindly assist please,
Thanks
Try:
Allan
I've tried it but not working, I have this error message
localhost says:DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1Hi Allan,
I just found the solution,
Here is the getformatter I finally used:
->getFormatter( 'Format::datetime', array('from' => 'Y-m-d H:i:s','to' => 'd/m/Y H:i') )I finally found the solution. This is the get formatter I finally used:
Thanks - good to hear you have it working now. The
datetimefunction I suggested above requires 1.7.0 or newer. With an older version of the library it would indeed throw a JSON error.Allan