Date Time Picker - Setting Opening Date and Time

Roger picture Roger · Sep 23, 2011 · Viewed 26.7k times · Source

I'm using this nifty little date and time picker [ http://trentrichardson.com/examples/timepicker/ ]. How can I set the date and time for when the picker opens?

Answer

John Zumbrum picture John Zumbrum · Aug 10, 2012

If you're using this on a form, set it from a hidden input.

$(document).ready(function () {
        $("#Date").datetimepicker({
            ampm: true
        });

        var date = new Date(
            Date.parse(
                $('#DatePicker').val(),
                "mm/dd/yyyy hh:MM tt"
            )
        );
        $('#Date').datetimepicker('setDate', date);
    });

HTML Form:

<input type="hidden" id="DatePicker" />
<input type="text" id="DatePicker" value="fromyourdatabase" />