time wont show time in textfield with datetimepicker

Loko

I have this field where I can insert the date and time through a datetimepicker:

<script>
     $(function() {
        $('#datepicker').datetimepicker({dateFormat: 'dd-mm-yy'});
     });
</script>

When I select the date and time, it will show the date and time perfectly in the textfield. Also when I press the submit button it will store the date and time perfectly through a DateTime() type in the database. Now I format the date that I read from the database from y-m-d to d-m-y in a function which is working fine. The problem is, if I go back to the page I submitted the date time in, it shows all the information I submitted in the input fields, except for the time. It only shows the date.

This is my input field:

<input type="text" name="date" value={{$date}} id='datepicker'>

When I var_dump($date); a few lines before the input field, I get the date and time perfectly like I want it:

11-04-2015 09:09

but in the textfield it shows:

11-04-2015

So there is nothing wrong with the variable $date.

When I submit again, it will save 11-04-2014 00:00:00.

Which makes me think there's something wrong with the format the default value is displayed in the textfield.

I already tried:

dateFormat: 'dd-mm-yy HH::mm'

in the script.

I use:

https://jqueryui.com/datepicker/

and:

http://trentrichardson.com/examples/timepicker/

EDIT:

Timepicker format JS:

timeFormat: 'HH:mm'
Alvaro Montoro

This is a typographical error in this line:

<input type="text" name="date" value={{$date}} id='datepicker'>

The date needs to go between quotes as the rest of the attributes. Otherwise it will stop at the first space break.

Right now, using the date that you specified, the generated code will look like this:

<input type="text" name="date" value=11-04-2015 09:09 id='datepicker'>

You can even see how StackOverflow highlights the "09:09" in a different color. And if you run the code snippet, you'll see that only the date is displayed.

Now, if you wrap the value between quotes, the result will be:

<input type="text" name="date" value="11-04-2015 09:09" id='datepicker'>

And the text field will display both date and time, so the datepicker will also process the time instead of ignoring it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related