Saving the time with Bootstrap DateTimePicker (2)

Saving the time with Bootstrap DateTimePicker (2)

Edwin1966Edwin1966 Posts: 9Questions: 4Answers: 0
edited September 2015 in Editor

Bootstrap DateTimePicker (2) has an example with no time information saved.
When I use the time component I've got a problem.
Date and time are shown OK from the database.
But on changing the date and time of the field with the picker, the date is saved OK but the time is lost (set to 00:00).
The info is also send correctly to my php-script:

data[row_1][todo][deadline]:"24-09-2015+10:44"

Any ideas?
I'm using this php code:

Field::inst( 'todo.deadline' )
            ->validator( 'Validate::dateFormat', array("empty"=>false, "format"  => "d-m-Y H:i", "message" => "Enter like this: dd-mm-jjjj hh:mm"))
            ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y H:i' )
            ->setFormatter( 'Format::date_format_to_sql', 'd-m-Y H:i' ),

and this javascript code:

{
                label: "deadline:",
                name: "todo.deadline", 
                type: "datetime",
                opts: {
                    showTodayButton: true,
                    format: 'DD-MM-YYYY HH:mm'
                },
                dateImage: "calender.png"
            },

This question has an accepted answers - jump to answer

Answers

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

    Hi,

    What you need to do here is use the datetime formatter and give it to and from parameters. This is required because the formatters you are using at the moment only operate with dates, not times as well.

    So you might end up with:

        Field::inst( 'todo.deadline' )
                ->validator( 'Validate::dateFormat', array(
                    "empty"=>false,
                    "format"  => "d-m-Y H:i",
                    "message" => "Enter like this: dd-mm-jjjj hh:mm")
                )
                ->getFormatter( 'Format::datetime', array(
                    'from' => 'Y-m-d H:i:00',
                    'to'   => 'd-m-Y H:i'
                ) )
                ->setFormatter( 'Format::datetime', array(
                    'from' => 'd-m-Y H:i',
                    'to'   => 'Y-m-d H:i:00'
                ) )
    

    Regards,
    Allan

  • Edwin1966Edwin1966 Posts: 9Questions: 4Answers: 0

    Great, that's what I needed.
    Thanks.

This discussion has been closed.