Tempus-dominus: Set default time in datetimepicker

Created on 24 May 2015  路  12Comments  路  Source: Eonasdan/tempus-dominus

Hi,

I'm using the datetimepicker function for pick date and time,

$('#end').datetimepicker({
format: 'DD-MM-YYYY HH:mm',
collapse:false,
sideBySide:true,
useCurrent:false,
showClose:true
});

It is picking the date with the time 00:00 by default, Is there any way to set the default time value (e.g 23:00)?

u0-weu-d3-b947b2d6fc14439f06f9982afb4ea6e8 pimgpsh_fullsize_distr

Thanks

Most helpful comment

Proposed workaround above erases the first selected date.

Corrected workaround:

$('.datetime-picker').on('dp.change', function(e) {
    if (e.oldDate === null) {
        $(this).data('DateTimePicker').date(new Date(e.date._d.setHours(20, 00, 00)));
    }
});

All 12 comments

in the dev branch you might be able to set the viewDate, otherwise you can set the date. In either case you will have to set both date and time

$('#end').datetimepicker({
format: 'DD-MM-YYYY HH:mm',
collapse:false,
sideBySide:true,
useCurrent:false,
showClose:true,
viewDate:'23-04-2015 23:00'
});
it tried like this.but it is not working

@Fitzerbirth You already found a solution for it? viewDate also not working for me.

viewDate is in the dev branch

Yes :)

"eonasdan-bootstrap-datetimepicker": "https://github.com/Eonasdan/bootstrap-datetimepicker.git#development"

Otherwise I would get the error mesage that the option isn't recognized.

please post a fiddle of your issue

http://jsfiddle.net/f4nhwjaw/1/

I would expect that 2015-01-01 23:59:59 is preselected in the picker.

EDIT:
I just see it's AM/PM but the issue is the same.

@Fitzerbirth A workaround could be:

    $('.datetime-picker').on('dp.change', function(e) {
        if (e.oldDate === null) {
            $(this).data('DateTimePicker').date(new Date(new Date().setHours(23, 59, 59)));
        }
    });

Proposed workaround above erases the first selected date.

Corrected workaround:

$('.datetime-picker').on('dp.change', function(e) {
    if (e.oldDate === null) {
        $(this).data('DateTimePicker').date(new Date(e.date._d.setHours(20, 00, 00)));
    }
});

use this

$('#end').datetimepicker({
dateFormat: 'yy-mm-dd',
collapse:false,
sideBySide:true,
useCurrent:false,
showClose:true,
hour : '23',
minute :'00'
});

How to set the date for inline bootstrap datetimepicker.
I used jQuery ('#datetimepicker1').data('DateTimePicker).date('1/10/2017 12:34:24').
Is there any other way to set date and time since it throws error

@ramppt Please next time debug your code you have horrible error on your code:
jQuery ('#datetimepicker1').data('DateTimePicker).date('1/10/2017 12:34:24')

If you look very closely you have skipped a ' on this data('DateTimePicker)

As this a solution given that currently works this will be close and locked

Was this page helpful?
0 / 5 - 0 ratings

Related issues

malhayek2014 picture malhayek2014  路  4Comments

am11 picture am11  路  6Comments

callum-resdiary picture callum-resdiary  路  4Comments

miraclebg picture miraclebg  路  3Comments

thw0rted picture thw0rted  路  5Comments