Datetime manipulation on Datatables and Editor

Datetime manipulation on Datatables and Editor

mihalispmihalisp Posts: 127Questions: 22Answers: 0

Hi,I have found it difficult to manipulate Datetime SqlServer field on Datatables and Editor

1) Allan,in this example

   https://editor.datatables.net/examples/dates/formatting.html

there is no Server Side script.It is missing.

I want to get it in Editor and Datatable in format 25/12/2019 22:30 .
When i use

    ->getFormatter( Format::dateSqlToFormat( 'd/m/Y H:i' ) )

the Datatable field it shows 'invalid date'.

When i use

   ->getFormatter( Format::dateTime( 'Y-m-d H:i:s', 'd/m/Y H:i' ) )

it returns 'null' date in JSON and in Datatable it shows only '01/01/1970 02:00'.

If i don't use getFormatter,it works on the Datatable (but it does not sort the dates in a right way),but in the Editor field it shows the date in format '2019-04-30 17:49:00.000' (it comes straight from the db?) which i don't want.I want this 25/12/2019 22:30.

In Editor i use

            def: function () { return new Date(); },
            type: "datetime" ,
            format: 'DD/MM/YYYY HH:mm'

but this formati is only for the new user inserted dates not the dates already in db and ready to be edited.

In the Datatable,I render it as follows so that i can sort the Start_date properly.

      { data: "db.date", "title": "Start_date" ,"render": function(data, type, full) {
       if (type == 'display')
           return moment(new Date(data)).locale('el').format('DD/MM/YYYY HH:mm');
       else
          return moment(new Date(data)).format('YYYY/MM/DD HH:mm:ss');             
      } }

2) When i send the date back to db ,what setFormatter should i use?
Is

  ->setFormatter( Format::dateTime( 'd/m/Y H:i', 'Y-m-d H:i:s' ) )

ok?

Thank you in advance.

Answers

This discussion has been closed.