Editor field formatter from unix time
Editor field formatter from unix time
I'm not sure how to get the time converted from unix (like '1370363054') to a more human readable format.
I've tried this, but no luck so far:
[code]
....
$editor = Editor::inst( $db, 'positions' )
->fields(
Field::inst('pos'),
Field::inst('data')
->setFormatter( 'Format::date_format_to_sql', 'D, d M y' ),
....
[/code]
It still displays in unix timestamp.
Also, does this conversion affect sorting?
I've tried this, but no luck so far:
[code]
....
$editor = Editor::inst( $db, 'positions' )
->fields(
Field::inst('pos'),
Field::inst('data')
->setFormatter( 'Format::date_format_to_sql', 'D, d M y' ),
....
[/code]
It still displays in unix timestamp.
Also, does this conversion affect sorting?
This discussion has been closed.
Replies
[code]
Field::inst('data')
->getFormatter( function ($val) {
return date( 'D, d M y', $val );
} )
[/code]
The built in `Format::date_format_to_sql` methods expected the date in ISO8601, so you need to have your own formatter - in this case using date to convert to what you want.
What I haven't got there is a set formatter. The set formatter will take whatever you submit (what will that be?) and convert it into what is stored in the database. In this case I presume you'll want to convert it to a unit timestamp.
> Also, does this conversion affect sorting?
It can yes. DataTables will correctly sort any string as a date if `Date.parse()` can parse the string. if it can't you either need to use orthogonal data (through mData / mRender) or a sorting plug-in.
Allan
I've mixed up set formatter with the get formatter. For now I won't be using editing for this table, so all I needed was the correct get formatter.