Date time Picker

Asked

Viewed 125 times

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 me to open the modal it starts today it is to open in 1979.

I’ve tried to put start: Date(); but if I do it every day before today they’re disabled.

  • which is the plugin used, you could provide the link

2 answers

2


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

$('.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 event show, which will pick up the current date as soon as the calendar opens:

$('.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());
});

1

Add useCurrent: false in 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 you set the field... as soon as 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 that 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 catch the time with javascript

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

now just set the NOVA_DATA

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

Here you also have the documentation link https://eonasdan.github.io/bootstrap-datetimepicker/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.