DataTable Editor getFormatter for date.
DataTable Editor getFormatter for date.
bbrindza
Posts: 316Questions: 73Answers: 1
I am using alphanumeric date columns from my DB2 table that are formatted as YYYMMDD.
I need to covert these columns to m/d/Y in the front-end.
I tried to using
->getFormatter('Format::datetime', array(
'from' => 'Ymd',
'to' => 'm/d/Y'
) )
unfortunately it return null values .
Here is the piece of code I am using. I seems that I may not have this right.
Field::inst('NWFF.MTTRAN.createDate')
->getValue('')
->getFormatter(function ($val, $data, $opts) {
switch ($data['NWFF.MTTRAN.TNSTAT']) {
case 'P':
return $data['NWFF.MTTRAN.TNWDTE'];
}
switch ($data['NWFF.MTTRAN.TNPM#']) {
case ($data > 0):
return $data['NWFF.MTTRAN.TNPDTE'];
}
switch ($data['NWFF.MTTRAN.TNDT#']) {
case ($data > 0):
return $data['NWFF.MTTRAN.TNDDTE'];
}
switch ($data['NWFF.MTTRAN.TNWO#']) {
case ($data > 0):
return $data['NWFF.MTTRAN.TNWDTE'];
}
})
->getFormatter('Format::datetime', array(
'from' => 'Ymd',
'to' => 'm/d/Y'
) ),
Thanks in advance
This question has an accepted answers - jump to answer
Answers
I think it would be easier to do it on the client. There are two datetime options -
displayFormat
andwireFormat
. To change how the field is displayed, tweak thedisplayFormat
.Colin
Colin , I am looking for an example that is for the columns on the front end .
This example shows client-side formatting, and this one on the server,
Colin
Thanks for the example Colin. I play around with this.