简体   繁体   中英

Remove the time in JQUERY DATETIMEPICKER

How can I disable the past date in datetimepicker2,

For example: I choose July 1, 2015 in datetimepicker1 then the date datetimepicker2 will be disable from July 1, 2015 and the past of the July 1, 2015. Also how to make the time will not appear in the textbox when i choose date.

Here's the screen capture of the Datetimepicker

Here's the structure:

<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.min.css">
<script type="text/javascript" src = "js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.datetimepicker.full.js"></script> 

I know the src in the top is the directory of the jquery, I just place there if maybe you know this scenario.

//html
<input id ="textin" required>
<input id ="textout" required>

//script

<script>

    $('#textin').datetimepicker({
        step: 5
    });
    $('#textin').datetimepicker({
        minDate: 0
    });

    $('#textout').datetimepicker({
        step: 5
    });
    $('#textout').datetimepicker({
        minDate: 0
    });
</script>

This should do the trick:

var data = {
  format: 'd/m/Y', //date format
  timepicker: false //hide time
};

const $in = $('#textin'), $out = $('#textout');

$in.datetimepicker(data);
$out.datetimepicker(data);

$in.on('change', function() {

  var minDate = $in.val();
  if (minDate) {
    minDate = minDate.split('/');
    console.log(minDate);
    minDate = new Date(minDate[2], minDate[1] - 1, minDate[0], 0, 0);
  } else {
    minDate = new Date(0, 0, 0, 0, 0);
  }
  data.minDate = minDate;
  $out.datetimepicker(data);

});

Try it out on jsfiddle: https://jsfiddle.net/maxbilbow/2ge1gj4j/5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM