DateRangePicker (http://www.daterangepicker.com/) is creating wrong values. When, for example, I select value 13:00 it shows up in input that it's 01:00
I have enabled timePicker24Hour to true so I dont really know what is the problem
Web page code
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'), 10),
locale: {
format: 'YYYY-MM-DD hh:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />
Does anyone have had this bug or I have configured something wrong?
Your issue is that the format you're outputting back to the input (through the locale) is of the format hh:mm, which is the 12-hour format (mm). You want HH instead, making the entire format YYYY-MM-DD HH:mm. The datepicker itself is set to 24-hour format by doing timePicker24Hour: true as you were doing.
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'),10),
locale: {
format: 'YYYY-MM-DD HH:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />
You need uppercase HH(24h format) to your date format
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'),10),
locale: {
format: 'YYYY-MM-DD HH:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />
Related
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" integrity="sha512-AIOTidJAcHBH2G/oZv9viEGXRqDNmfdPVPYOYKGy3fti0xIplnlgMHUGfuNRzC6FkzIo0iIxgFnr9RikFxK+sw==" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css" integrity="sha512-f0tzWhCwVFS3WeYaofoLWkTP62ObhewQ1EZn65oSYDZUg1+CyywGKkWzm8BxaJj5HGKI72PnMH9jYyIFz+GH7g==" crossorigin="anonymous" />
<h1>date</h1>
<input type="text" name="input_time" id="input_time">
<script>
$('#input_time').datetimepicker({
format:'h:i A',
validateOnBlur: false,
formatTime: 'h:i A',
step: 15 ,
datepicker:false
})
$('#input_time').datetimepicker('option', 'minTime','6:00 PM' );
</script>
I wanted to change minimum time of a datetimepicker dynamically. but nothing seems to work
The pattern you're using to update the plugin options after initialization is for jQueryUI components.
For the DateTimePicker library you need to use the setOptions method, like this:
$('#input_time').datetimepicker({
format: 'h:i A',
validateOnBlur: false,
formatTime: 'h:i A',
step: 15,
datepicker: false
})
$('#input_time').datetimepicker('setOptions', { minTime: '18:00' });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" integrity="sha512-AIOTidJAcHBH2G/oZv9viEGXRqDNmfdPVPYOYKGy3fti0xIplnlgMHUGfuNRzC6FkzIo0iIxgFnr9RikFxK+sw==" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css" integrity="sha512-f0tzWhCwVFS3WeYaofoLWkTP62ObhewQ1EZn65oSYDZUg1+CyywGKkWzm8BxaJj5HGKI72PnMH9jYyIFz+GH7g==" crossorigin="anonymous"
/>
<h1>date</h1>
<input type="text" name="input_time" id="input_time">
Note that I used a 24 hour time format in this example as there appears to be a bug to do with daylight savings/UTC interpretation in the library when you set 6:00 PM it shows 5:00 PM as the minimum for my locale.
I have checked lot of tutorials and QAs in Google and tried with all permutation and combination tricks. Still my calender is not restricted with maxDate and minDate as I set. Please can someone check and let me know whats wrong with my code.
my javascript function is
$(function () {
$("[id$=txtPaymentDate]").datepicker({
maxDate: "+0D",
showOn: 'button',
dateFormat: 'mm-dd-yyyy',
buttonImageOnly: true
});
});
...and my body code:
<td>
<asp:TextBox ID="txtPaymentDate" runat="server" CssClass="form-control" placeholder="(YYYY-MM-DD)"></asp:TextBox>
<span id="spnAltContactNumber" style="color: Red;" runat="server"></span>
</td>
EDIT
Even though I've set dateFormat as 'yyyy-mm-dd', it is still showing the date as mm/dd/yyyy.
I have these following scripts. Is there any extra is required?
<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
For this maxDate and minDate does not work.Instead u need to use startDate and endDate as below.
$("[id$=txtPaymentDate]").datepicker({
showOn: 'button',
dateFormat: 'mm-dd-yyyy',
buttonImageOnly: true,
startDate: '-5d',//previous date
endDate: new Date()//current date
});
Happy coding
change textbox accoring to .net
$( function() {
$( "#txtPaymentDate" ).datepicker({dateFormat: 'dd M yy',maxDate: 1});
} );
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<td>
<p>Date: <input type="text" id="txtPaymentDate"></p>
</td>
it should be maxDate: 1
$( "#datepicker").datepicker({dateFormat: 'dd M yy',maxDate: 1});
Hello i am having a very strange problem with daterangepicker.
I load all the necessary JavaScript files before the </body> tag.
Here are the js files:
<script src="https://www.example.com/members/js/jquery/jquery-2.2.3.min.js"></script>
<script src="https://www.example.com/members/js/bootstrap/bootstrap.min.js"></script>
<script src="https://www.example.com/members/js/jquery/jquery-ui.min.js"></script>
<script src="https://www.example.com/members/js/daterangepicker/moment.min.js"></script>
<script src="https://www.example.com/members/js/daterangepicker/daterangepicker.js"></script>
<script src="https://www.example.com/members/js/slimscroll/jquery.slimscroll.min.js"></script>
<script src="https://www.example.com/members/js/icheck/icheck.min.js"></script>
<script src="https://www.example.com/members/js/fastclick/fastclick.js"></script>
<script src="https://www.example.com/members/js/app/app.min.js"></script>
<script>
$('#reservation1').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
dateFormat: 'YYYY-MM-DD'
});
$('#reservation2').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
dateFormat: 'YYYY-MM-DD'
});
$('#reservation3').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
dateFormat: 'YYYY-MM-DD'
});
</script>
and then i get this:
Shouldn't it display the current date? and shouldn't i be able to choose some years?
Any help will be highly appreciated!!!
Currently, I'm using Bootstrap 3 Datepicker from this source
I have 2 datetimepicker on my system. (startTime, endTime).
I tried but don't know how to set minDate for endTime from startTime value whenever startTime value changed. Even it don't jump on change event.
Please point me what am I missing.
Here is my code
Many thanks.
You need to use the change event and minDate() function like
$('#txtStartTime').datetimepicker({
showTodayButton: true,
format: 'MM/DD/YYYY HH:mm',
sideBySide: true,
maxDate: moment()
}).on('dp.change', function(e) {
$('#txtEndTime').data("DateTimePicker").minDate(e.date)
});
$('#txtEndTime').datetimepicker({
showTodayButton: true,
format: 'MM/DD/YYYY HH:mm',
sideBySide: true
});
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div class="row">.</div>
<div class="col-md-3">
<input class="form-control datetimepicker" id="txtStartTime" type='text' />
</div>
<div class="col-md-3">
<input class="form-control datetimepicker" id="txtEndTime" type='text' />
</div>
I use the datepicker function from jquery. Now I have integrated a inline calendar. It should be possible to click on one day in the shown month and then submit a form or change the url. I need the new date added to the url so i can jump to this date.
But my code won't change the value of the input - and i don't know why.
Here my code:
In the head area:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="templates/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="templates/js/bootstrap-datepicker.de.js"></script>
The HTML:
<form method="get" action="index.php">
<div class="form-group">
<div class="minicalendar"></div>
<input class="form-control" type="text" name="submitDate" id="submitDate" />
</div>
</form>
The JS:
$('.minicalendar').datepicker({
format: "dd.mm.yyyy",
todayBtn: true,
language: "de",
calendarWeeks: true,
todayHighlight: true,
onSelect: function(dateText, inst) {
$('#submitDate').val(dateText);
}
});
Do you know why? I was searching for a time now but I wasn't able to find a solution that works ...
Thanks.
You are binding the datepicker to adiv instead of aninput.
<input id="datepicker" />
$('#datepicker').datepicker({
//...
});
You also don't need to change the input text with the onSelect event. The widget will do thix automatically.
$('#submitDate').datepicker({
format: "dd.mm.yyyy",
todayBtn: true,
language: "de",
calendarWeeks: true,
todayHighlight: true,
onSelect: function(dateText, inst) {
$('#submitDate').val(dateText);
}
});
Use this. Datepicker won't bind to a <div> it has to be an <input> element. Check this link for more examples.
Here is the code from JQuery UI DatePicker :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
The input id has to be the same that the element selected in JQuery.