Datapicker calendar chage within 1 year range
Sorry about the code — it's not all completed with HTML, just for an idea.
$('#Datepicker1').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch), // its 2012-2018 (variable)
//yearRange: "year:year",
showButtonPanel: true,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
);
$('#Datepicker2').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch),
yearRange: "year:year",
showButtonPanel: true,
beforeShow: function(input, inst)
var from = $('#Datepicker1').val();
if(from)
var year = from.substring(from.length - 4, from.length);
var day = from.substring(0, 2);
var month = from.substring(3, 5);
console.log('beforeShow2 =' + day+"."+month+"."+year);
$(this).datepicker('option','maxDate',new Date(parseInt(year)+1,parseInt(month)-1,day));
console.log('maxDate TO =' + new Date(parseInt(year)+1,parseInt(month)-1,day));
$(this).datepicker('option','minDate',new Date(year,parseInt(month)-1,day));
else
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
).datepicker("setDate", new Date(DEStorage.get('statementsDateTo')));
I have 2 calendars. I want to do something like this: when I select first date, the second date should be within 1 year range gab. Example: I select 10 June 2012 for the first date, then the second date should be 10 June 2012 until 10 june 2013 (1 year gab). When I select something from first calendar, the second calendar should update automatically and first date should not be greater than second date. any help please?
jquery jquery-ui-datepicker
add a comment |
Sorry about the code — it's not all completed with HTML, just for an idea.
$('#Datepicker1').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch), // its 2012-2018 (variable)
//yearRange: "year:year",
showButtonPanel: true,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
);
$('#Datepicker2').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch),
yearRange: "year:year",
showButtonPanel: true,
beforeShow: function(input, inst)
var from = $('#Datepicker1').val();
if(from)
var year = from.substring(from.length - 4, from.length);
var day = from.substring(0, 2);
var month = from.substring(3, 5);
console.log('beforeShow2 =' + day+"."+month+"."+year);
$(this).datepicker('option','maxDate',new Date(parseInt(year)+1,parseInt(month)-1,day));
console.log('maxDate TO =' + new Date(parseInt(year)+1,parseInt(month)-1,day));
$(this).datepicker('option','minDate',new Date(year,parseInt(month)-1,day));
else
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
).datepicker("setDate", new Date(DEStorage.get('statementsDateTo')));
I have 2 calendars. I want to do something like this: when I select first date, the second date should be within 1 year range gab. Example: I select 10 June 2012 for the first date, then the second date should be 10 June 2012 until 10 june 2013 (1 year gab). When I select something from first calendar, the second calendar should update automatically and first date should not be greater than second date. any help please?
jquery jquery-ui-datepicker
add a comment |
Sorry about the code — it's not all completed with HTML, just for an idea.
$('#Datepicker1').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch), // its 2012-2018 (variable)
//yearRange: "year:year",
showButtonPanel: true,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
);
$('#Datepicker2').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch),
yearRange: "year:year",
showButtonPanel: true,
beforeShow: function(input, inst)
var from = $('#Datepicker1').val();
if(from)
var year = from.substring(from.length - 4, from.length);
var day = from.substring(0, 2);
var month = from.substring(3, 5);
console.log('beforeShow2 =' + day+"."+month+"."+year);
$(this).datepicker('option','maxDate',new Date(parseInt(year)+1,parseInt(month)-1,day));
console.log('maxDate TO =' + new Date(parseInt(year)+1,parseInt(month)-1,day));
$(this).datepicker('option','minDate',new Date(year,parseInt(month)-1,day));
else
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
).datepicker("setDate", new Date(DEStorage.get('statementsDateTo')));
I have 2 calendars. I want to do something like this: when I select first date, the second date should be within 1 year range gab. Example: I select 10 June 2012 for the first date, then the second date should be 10 June 2012 until 10 june 2013 (1 year gab). When I select something from first calendar, the second calendar should update automatically and first date should not be greater than second date. any help please?
jquery jquery-ui-datepicker
Sorry about the code — it's not all completed with HTML, just for an idea.
$('#Datepicker1').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch), // its 2012-2018 (variable)
//yearRange: "year:year",
showButtonPanel: true,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
);
$('#Datepicker2').datepicker(
changeYear: true,
dateFormat: 'dd.mm.yy',
maxDate: 0,
minDate:new Date(_this.minDateSearch),
yearRange: "year:year",
showButtonPanel: true,
beforeShow: function(input, inst)
var from = $('#Datepicker1').val();
if(from)
var year = from.substring(from.length - 4, from.length);
var day = from.substring(0, 2);
var month = from.substring(3, 5);
console.log('beforeShow2 =' + day+"."+month+"."+year);
$(this).datepicker('option','maxDate',new Date(parseInt(year)+1,parseInt(month)-1,day));
console.log('maxDate TO =' + new Date(parseInt(year)+1,parseInt(month)-1,day));
$(this).datepicker('option','minDate',new Date(year,parseInt(month)-1,day));
else
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
,
onClose : function (dateSelected)
$('#Datepicker1').datepicker('option','yearRange','c-1:c+1');
$('#Datepicker2').datepicker('option','yearRange','c-1:c+1');
).datepicker("setDate", new Date(DEStorage.get('statementsDateTo')));
I have 2 calendars. I want to do something like this: when I select first date, the second date should be within 1 year range gab. Example: I select 10 June 2012 for the first date, then the second date should be 10 June 2012 until 10 june 2013 (1 year gab). When I select something from first calendar, the second calendar should update automatically and first date should not be greater than second date. any help please?
jquery jquery-ui-datepicker
jquery jquery-ui-datepicker
edited Nov 14 '18 at 10:39
Armali
7,3051137101
7,3051137101
asked Nov 14 '18 at 10:05
HalilHalil
267
267
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try this..set to maxDate first datepicker onClose function
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297566%2fdatapicker-calendar-chage-within-1-year-range%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this..set to maxDate first datepicker onClose function
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
add a comment |
Try this..set to maxDate first datepicker onClose function
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
add a comment |
Try this..set to maxDate first datepicker onClose function
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
Try this..set to maxDate first datepicker onClose function
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
$("#searchFromDate").datepicker(
dateFormat:'yy-mm-dd',
onClose: function( selectedDate )
var date = $(this).datepicker('getDate');
var todate=new Date(date.getFullYear()+1,date.getMonth(),date.getDate())
$("#searchToDate" ).datepicker( "option", "maxDate", todate );
$("#searchToDate" ).datepicker( "option", "minDate", selectedDate );
);
$("#searchFromDate").datepicker("setDate", new Date());
$("#searchToDate").datepicker(dateFormat:'yy-mm-dd');
$("#searchToDate").datepicker("setDate", new Date());
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
</head>
<body>
<p>Date: <input type="datepicker" id="searchFromDate"></p>
<p>Date: <input type="datepicker" id="searchToDate"></p>
</body>
answered Nov 14 '18 at 11:09
Sooriya DasanayakeSooriya Dasanayake
9021411
9021411
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297566%2fdatapicker-calendar-chage-within-1-year-range%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown