Problem using getFormatter
Problem using getFormatter
Hello!
I have a small Problem while using the getFormatter. I want to Format a datetime field from a mysql database to the following format HH:MM:SS with leeding zeros. If i understand it correct, the formatstring is like the date function from php. I used the following string.
[code]
$editor = Editor::inst( $db, 'timetable' )
->field(
Field::inst( 'StartTime')
->set( false )
->getFormatter( 'Format::date_sql_to_format', 'H:i:s' )
.....
[/code]
I expect the following timestamp "StartTime":"08:30:00", but in the JSON Result I found this one: "StartTime":"23:15:08". The stored Date in the mysql database is the following one: "2013-11-05 08:30:00"
What's gone wrong?
Thanks for your assistance.
Best regards
I have a small Problem while using the getFormatter. I want to Format a datetime field from a mysql database to the following format HH:MM:SS with leeding zeros. If i understand it correct, the formatstring is like the date function from php. I used the following string.
[code]
$editor = Editor::inst( $db, 'timetable' )
->field(
Field::inst( 'StartTime')
->set( false )
->getFormatter( 'Format::date_sql_to_format', 'H:i:s' )
.....
[/code]
I expect the following timestamp "StartTime":"08:30:00", but in the JSON Result I found this one: "StartTime":"23:15:08". The stored Date in the mysql database is the following one: "2013-11-05 08:30:00"
What's gone wrong?
Thanks for your assistance.
Best regards
This discussion has been closed.
Replies
I have the JSON result now updated a few times. The time that I get displayed is always equal to the current and not stored in the database time.
Why is that?
Thank you!
Do you mean that if you load the table, all rows are showing the current time in that specific column? Or is it that the field is updated to the current time when you edit the row?
Thanks,
Allan
if I load the data from the database table all rows are showing the current time in the column...
Here is a excerpt from the JSON result
[code]
{
"id":-1,
"error":"",
"fieldErrors":[],
"data":[],
"aaData":[
{
"DT_RowId":"row_55",
"StartTime":"11:46:31",
"EndTime":"11:46:31",
"mitarbeiter_id":"1",
"kostenstellen_id":"2",
"stunden_stamm_id":"3"
},{
"DT_RowId":"row_58",
"StartTime":"11:46:31",
"EndTime":"11:46:31",
"mitarbeiter_id":"1",
"kostenstellen_id":"1",
"stunden_stamm_id":"3"
},{
"DT_RowId":"row_60",
"StartTime":"11:46:31",
"EndTime":"11:46:31",
"mitarbeiter_id":"1",
"kostenstellen_id":"2",
"stunden_stamm_id":"1"
}
]
}
[/code]
Thanks!
do you need further data?
Thanks!
Until then, you can use a little closure function to get the formatting you want:
[code]
->set( false )
->getFormatter( function ( $val, $data ) {
return date( 'H:i:s', strtotime($val) );
} ),
[/code]
Regards,
Allan
Regards,
Thomas