My date field field so that it has this format dd/mm/yyyy and not this yyyy-mm-dd format?

My date field field so that it has this format dd/mm/yyyy and not this yyyy-mm-dd format?

klermannklermann Posts: 277Questions: 67Answers: 1

Hello Allan, how should I format my date field field so that it has this format dd/mm/yyyy and not this yyyy-mm-dd format?

This question has accepted answers - jump to:

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    use momentjs plugin in the column render to format the date how you want.

    Here is an example http://jsbin.com/didequg/edit?js,output , look and the columns section towards the top.

    http://momentjs.com

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    See also this blog post.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Allan and in the editor how should I use this function!

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    The fact that Editor is being used on the same table should make no difference. You would use it in exactly the same way as described in the blog post I linked to.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1
    edited August 2017

    Can you tell me why the date was not changed?
    Required format is dd/mm/yyyy

    I placed above the editor

                $.fn.dataTable.moment( 'HH:mm MMM D, YY' );
                $.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' );
    
                $.fn.dataTable.moment = function ( format, locale ) {
                    var types = $.fn.dataTable.ext.type;
    
                    // Add type detection
                    types.detect.unshift( function ( d ) {
                        return moment( d, format, locale, true ).isValid() ?
                            'moment-'+format :
                            null;
                    } );
    
                    // Add sorting method - use an integer for the sorting
                    types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
                        return moment( d, format, locale, true ).unix();
                    };
                };
    
                editor = new $.fn.dataTable.Editor( {....
    
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    The moment sorting plug-in won't effect Editor at all. It will effect the sorting.

    I don't know where on your page that input element is. Is it a datetime field? If so use the format option that is documented for that field type.

    Allan

This discussion has been closed.