DataTable Editor getFormatter for date.

DataTable Editor getFormatter for date.

bbrindzabbrindza Posts: 300Questions: 69Answers: 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

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    I think it would be easier to do it on the client. There are two datetime options - displayFormat and wireFormat. To change how the field is displayed, tweak the displayFormat.

    Colin

  • bbrindzabbrindza Posts: 300Questions: 69Answers: 1

    Colin , I am looking for an example that is for the columns on the front end .

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    edited July 2021 Answer ✓

    This example shows client-side formatting, and this one on the server,

    Colin

  • bbrindzabbrindza Posts: 300Questions: 69Answers: 1

    Thanks for the example Colin. I play around with this.

Sign In or Register to comment.