Getting datepicker to count number of days and show the days in between
Hi,
Thank you for developing jQuery UI datepicker. It is so user-friendly and beautiful, we don't have to code a calendar all from scratch!
I am using the datepicker to show 2 calendars and it is working great! But I couldn't get the number of days to show and I couldn't get it to list out the days in between... Please help me! It might be some stupid mistake I made hahah.
For a start I couldn't even get it to count number of days...
My code:
- <script>
- $(document).ready(function() {
- $( "#from" ).datepicker({
- altField: "#alternate",
- altFormat: "DD, d MM, yy",
- //minimal date to select (today)
- minDate: new Date( (new Date()).getTime() ),
- maxDate: "+60D",
- onSelect: function(selected) {
- $("#to").datepicker("option","minDate", selected)
- // alert(date1);
- }
- });
- $( "#to" ).datepicker({
- altField: "#alternate1",
- altFormat: "DD, d MM, yy",
- minDate: new Date( (new Date()).getTime() + 3600*24*1000 ),
- maxDate:"+60D",
- onSelect: function(selected) {
- $("#from").datepicker("option","maxDate", selected)
- }
- });
- function calcDiff() {
- var date1 = $(this).datepicker('getDate');
- document.getElementById("alternate").value = date1;
- var date2 = $(this).datepicker('getDate');
- document.getElementById("alternate1").value = date2;
- var diff = 0;
- if (date1 && date2) {
- diff = Math.floor((date2.getTime() - date1.getTime()) / 86400000); // ms per day
- }
- $('#calculated').val(diff);
- }
- });
- </script>
My html for calculated is:
- <input type="text" id="calculated">
The 2 calendars are working so I won't show it here...
Is there something wrong with the code? I have coded it according to one of the reply here in the forum.
Please help! Thanks!