Problem using getFormatter

Problem using getFormatter

thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
edited November 2013 in Editor
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

Replies

  • thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
    Hi, I already ...

    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!
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    Hi,

    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
  • thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
    edited November 2013
    Hi 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!
  • thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
    Hi allan,

    do you need further data?

    Thanks!
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    Thanks of rate extra information. I see what the issue is now. The problem is that the Editor date formatting function assumes that only the date part of the timestamp will be used, so it actually truncates the time part. I'll address the tin the next update.

    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
  • thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
    Thanks a lot!

    Regards,

    Thomas
This discussion has been closed.