reformate date comes from json

reformate date comes from json

hanyelbanahanyelbana Posts: 24Questions: 0Answers: 0
edited September 2013 in Editor
Hi,
my
{ "mData": "created_at" }
return
2013-09-08 06:13:56

and I need to display only the date without time

How can I do that?

Thanks

Replies

  • allanallan Posts: 61,805Questions: 1Answers: 10,118 Site admin
    Are you using the Editor PHP libraries? If so, you can use the formatting functions:

    http://editor.datatables.net/docs/current/php/class-DataTables.Editor.Field.html#_getFormatter
    http://editor.datatables.net/docs/current/php/class-DataTables.Editor.Field.html#_setFormatter

    There are some helper date formatter functions built into the Editor libraries: http://editor.datatables.net/docs/current/php/class-DataTables.Editor.Format.html ( `DATE_ISO_8601` for example might be what you want).

    Regards,
    Allan
  • allanallan Posts: 61,805Questions: 1Answers: 10,118 Site admin
    I should also say that there are examples of using the formatter fields here: http://editor.datatables.net/release/DataTables/extras/Editor/examples/dates.html

    Allan
  • hanyelbanahanyelbana Posts: 24Questions: 0Answers: 0
    Hi,
    I do not set the date, I only read it from the data base.
    Please give me example, how can I change this row to format the display date:
    { "mData": "created_at" }
  • allanallan Posts: 61,805Questions: 1Answers: 10,118 Site admin
    There is an example in the link I posted:

    [code]
    Editor::inst( $db, 'users' )
    ->fields(
    Field::inst( 'first_name' ),
    Field::inst( 'last_name' ),
    Field::inst( 'updated_date' )
    ->validator( 'Validate::dateFormat_required', array(
    "format" => Format::DATE_ISO_8601,
    "message" => "Please enter a date in the format yyyy-mm-dd"
    ) )
    ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
    ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
    Field::inst( 'registered_date' )
    ->validator( 'Validate::dateFormat', 'D, d M y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, d M y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, d M y' )
    )
    ->process( $_POST )
    ->json();
    [/code]

    Allan
This discussion has been closed.