What can I do to configure columns to view all date fields on "DD-MM-YYYY" format?

What can I do to configure columns to view all date fields on "DD-MM-YYYY" format?

OdnumiOdnumi Posts: 4Questions: 2Answers: 0
edited March 2017 in Free community support

All my date fields appears as "YYYY-MM-DD" but I need to see them in the format "DD-MM-YYYY".
I search in the forum but only talks of filtering and BD saving data. I only need modify the views.

Y have all my fields in HTML as:

<div class="form-group col-sm-12"> <label for="terminado" class="col-sm-1 control-label">Terminado:</label> <div class="col-sm-2"><input id="terminado" name="terminado" type="text" class="form-control campos_fecha" autocomplete="off"> </div> [...]

And .js file as:

"ajax":{ "method":"POST", "url": "listar.php" }, "columns":[ {"data":"idproyecto", "bVisible": false }, {"data":"terminado"} [...]

Can you help me?

Replies

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    edited March 2017

    One option is to use moment.js and use columns.render to change the format. For example:

            render: function (data, type, row) {
              return moment(new Date(data).toString()).format('DD/MM/YYYY');
            }
    

    If you need to sort by the date you can add the datetime-moment plugin.

    Kevin

This discussion has been closed.