Date time picker

1

The code I have is this:

$('.form_datetime').datetimepicker({
    language:  'pt',
    format: 'yyyy-mm-dd hh:ii:ss',
    autoclose: true,
    todayBtn: true,
    minuteStep: 10
});

I want it when I open the modal it starts on today it is opening in 1979.

I have tried to put start: Date(); but if I do this every day before today they are disabled.

    
asked by anonymous 01.02.2018 / 21:18

2 answers

2

After starting the plugin, add this code that will update the date to the current one:

$('.form_datetime').datetimepicker('setDate', new Date());

Example:

$('.form_datetime').datetimepicker({
   language:  'pt',
   format: 'yyyy-mm-dd hh:ii:ss',
   autoclose: true,
   todayBtn: true,
   minuteStep: 10
}).datetimepicker('setDate', new Date());

Otherwise , you can use the show event, which will pick up the current date as soon as the calendar is opened:

$('.form_datetime').datetimepicker({
   language:  'pt',
   format: 'yyyy-mm-dd hh:ii:ss',
   autoclose: true,
   todayBtn: true,
   minuteStep: 10
}).on("show", function(){
   $(this).datetimepicker('setDate', new Date());
});
    
01.02.2018 / 22:07
1

Add useCurrent: false to your code, which should appear

$('.form_datetime').datetimepicker({
    language:  'pt',
    format: 'yyyy-mm-dd hh:ii:ss',
    autoclose: true,
    todayBtn: true,
    minuteStep: 10,
useCurrent: true
});

Another solution is to set the field ... once you open the modal.

Your modal has an id, right? we usually open the modal so $("#meumodal").modal();

Once you open the modal, you can set the value of the field within this modal ....

$("#meumodal").find('.form_datetime').val(NOVA_DATA);

The variable nova_data, you can create it with javascript, or with php .... a technique that I use a lot is, create an input

<input type="hidden" value="<?php echo date('Y-m-d H:i:s'); ?>" id="data_time_atual>

This makes it much easier to get the time with javascript

var hora = $("#data_time_atual").val();

Now just set NOVA_DATA

 var hora = $("#data_time_atual").val();
 $("#meumodal").find('.form_datetime').val(hora );

Here you also have the documentation link link

    
01.02.2018 / 21:49