Advertisement
Vurade

date counter

Jan 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <table style="border: 1px solid black;">
  2.                                 <tr>
  3.                                     <th>
  4.                                         Настаняване:
  5.                                     </th>
  6.                                     <td>
  7.                                         <input type="text" name="fromDate" id="fromDate" value="<?php echo date('01-m-Y'); ?>" />
  8.                       <input type="button" id="calendarButtonFrom" value="Избери дата" />
  9.                                     </td>
  10.                                 </tr>
  11.                                 <tr>
  12.                                     <th>
  13.                                         Напускане:
  14.                                     </th>
  15.                                     <td>
  16.                                         <input type="text" name="toDate" id="toDate" value="<?php echo date('05-m-Y'); ?>" readonly />
  17.                       <input type="button" id="calendarButtonTo" value="Избери дата" />
  18.                                     </td>
  19.                                 </tr>
  20.                                 <tr>
  21.                                     <th>
  22.                                         Общ период нощувки:
  23.                                     </th>
  24.                                     <td>
  25.                                         <input type="text" name="stay_days" id="stay_days" readonly>
  26.                                     </td>
  27.                                 </tr>
  28.                             </table>
  29.  
  30.  
  31. <script type="text/javascript">
  32.             Calendar.setup(
  33.               {
  34.                 inputField: "fromDate",
  35.                 button: "calendarButtonFrom",
  36.                 align: "Tr"
  37.               }
  38.             );
  39.             Calendar.setup({inputField: "toDate", button: "calendarButtonTo", align: "Tr"});
  40.             $("#fromDate").bind('input', function(){
  41.               alert("aaaa");
  42.             });
  43.  
  44.             var a = $('#fromDate').val();
  45.             var b = $('#toDate').val();
  46.  
  47.             function convertDigitIn(str){
  48.               return str.split('-').reverse().join('-');
  49.             }
  50.  
  51.             var a1 = convertDigitIn(a);
  52.             var b1 = convertDigitIn(b);
  53.        
  54.             function treatAsUTC(date) {
  55.               var result = new Date(date);
  56.               result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
  57.               return result;
  58.             }
  59.  
  60.             function daysBetween(startDate, endDate) {
  61.               var millisecondsPerDay = 24 * 60 * 60 * 1000;
  62.               return (treatAsUTC(endDate) - treatAsUTC(startDate)) / millisecondsPerDay;
  63.             }
  64.  
  65.             var result = daysBetween(a1, b1);
  66.             $('#stay_days').val(result);
  67. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement