I'm struck in a problem where i want to always have difference
of 7 days
between 2 dates
Suppose if my date is set to 01/01/2018 - 07/01/2018
(dd/mm/yy) then on click of next it give date as 08/01/2018 - 15/01/2018
(7 days addition)
similarly on click
of previous 08/01/2018 - 15/01/2018
should give 01/01/2018 - 07/01/2018
jsfiddle: http://jsfiddle.net/rU5Nc/2654/
Here is what i have tried:
$(document).ready(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: 'dd/mm/yy'
});
});
$(document).on("click", '.next-day', function () {
var date = $('#datepicker').datepicker('getDate');
date.setTime(date.getTime() + (1000*60*60*24))
$('#datepicker').datepicker("setDate", date);
});
$(document).on("click", '.prev-day', function () {
var date = $('#datepicker').datepicker('getDate');
date.setTime(date.getTime() - (1000*60*60*24));
$('#datepicker').datepicker("setDate", date);
});
.next-prev{
display: inline-block;
padding: 0px;
top: -45px;
position: relative;
right: -243px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<p>Date:
<input type="text" id="datepicker" value="01/01/2018 - 07/01/2018" />
</p>
<div class="next-prev">
<div class="next-day">
Next date >
</div>
<div class="prev-day">
previous date >
</div>
</div>
EDIT 1
my expected output:
Always next previous should have 7 days gap, without conflicting, and result should appear like below (maintaining 7 days gap on each click)
<br/>
<hr>
please don't worry on calendar display as i have multiple select in my project, producing same here is not possible, thanks
<p><input type="text" value="01/01/2018 - 07/01/2018"></p>