dateformat
dateformat
Hi,
in my example I tried to set a dateformat in this way:
{
label: "SellDate:",
name: "sellDate",
def: function () { var d = new Date(); return new Date(d.getFullYear(), 11, 31); },
type: "datetime",
dateFormat: "dd.mm.YYYY"
},
or
{
label: "Date:",
name: "_stocks_fees.date",
type: "datetime",
dateFormat: "dd.mm.YYYY"
}
but it seems that the dateFormat variables were ignored and the date in the form and in the tables is still YYYY-MM-DD.
What did I wrong?
Thanks for any support
Patrick
This question has an accepted answers - jump to answer
Answers
Its hard to say without a link to a test case. The code above looks okay. Have you included the Moment.JS library (which is returned for the
datetime
field if you are using a custom format.Allan
I included the http://momentjs.com/downloads/moment.js, but at my example http://wechselstube.host4free.de/start5.php it still don't work.
I tried it in the forms (e.g. on Edit) and also on the child table.
Ah. Two things:
format
for thedatetime
field type.format
option for Editor doesn't effect the format that is displayed in the DataTable. Only the value that is read by and shown in thedatetime
input element.If you want to use a different format in the DataTable, you'd need to return the format needed from the server-side. Editor's PHP libraries have formatters for that sort of thing.
Allan
This works not bad:
Field::inst( '_stocks_fees.date' )
->validator( 'Validate::dateFormat', array(
'empty' => false,
'format' => 'd.m.Y'
) )
->getFormatter( 'Format::datetime', array(
'from' => 'Y-m-d H:i:s',
'to' => 'd.m.Y'
) )
->setFormatter( 'Format::datetime', array(
'from' => 'd.m.Y',
'to' => 'Y-m-d H:i:s'
) )
but the datePicker ignore the format and still uses this format YYYY-MM-DD.
Have you a least advice for me how to fix this issue?
Thank you very very much
Patrick
Did you update the client-side Javascript to use
format
rather thandateFormat
?Allan
Yes that's was it:
Now it works as expected:
Thank you very much