Advertisement
Guest User

picker

a guest
Jun 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.   var today = new Date();
  3.  
  4.   format = function(date){
  5.     var day = ('0' + date.getDate()).slice(-2);
  6.     var month = ('0' + (date.getMonth() + 1)).slice(-2);
  7.     var year = date.getFullYear();
  8.     return (year + '-' + month + '-' + day);
  9.   }
  10.  
  11.   $('#checkout').val(format(today));
  12.   $('#checkin').val(format(today));
  13.  
  14.   $('#minusWeek').click(function(){
  15.     var lastWeek = new Date();
  16.     lastWeek.setDate(lastWeek.getDate() - 7);
  17.     $('#checkin').val(format(lastWeek));
  18.   });
  19.  
  20.   $('#minusMonth').click(function(){
  21.     var lastMonth = new Date();
  22.     lastMonth.setMonth(lastMonth.getMonth() - 1);
  23.     $('#checkin').val(format(lastMonth));
  24.   });
  25.  
  26.   $('#view').click(function(){
  27.     alert('Start: ' + $('#checkin').val() + "\n" + 'End: ' + $('#checkout').val());    
  28.   });
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement