customfields_fill_object() by default will format and beautify values, thus it will convert SQL date, which are stored in the universal format ISO 8601 (year-month-day) into the locale one.
You can workaround this by two ways:
- either reformat the date back to universal format with something like
$object->cf_invorderdate = date("Y-m-d", strtotime($object->customfields->commande->cf_coorderdate));
- either if you only intend to use $object->customfields->commande to copy these fields elsewhere (you don’t plan to print them out), you can just fetch the raw, unformatted values by setting the $pdfformat parameter to null:
customfields_fill_object(&$object, $fromobject = null, $outputlangs = null, $prefix = null,$pdfformat = false); // set $pdfformat to null to get non formatted values
For example with something like that:
customfields_fill_object(&$object, null, null, 'commande->raw',null); // this will store the raw custom fields values inside $object->customfields->commande->raw->cf_yourfield
This second method has the advantage to also work for other complex kind of fields types like constrained types (where you can’t just copy the formatted value, you need to use the ID as the field will only accept an int).
Of course, when the raw values will be copied and saved into your target fields, when these fields will be accessed on the Dolibar datasheet or ODT templates, these values will be formatted and beautified (you only get the raw fields but from the raw fields, CustomFields will deduce the proper formatting it has to apply as long as both the source field and target field have the same SQL structure. eg: a source field that is constrained on a table, the target field should also be constrained on the same table).
So I would advise you to use the second method if you want to generalize your solution as it is pretty simple, elegant and robust, but if it’s only for a specific, punctal case, then the first method can be appropriate.