Setting start and end dates

752 views
Skip to first unread message

A.S.

unread,
Feb 13, 2014, 1:05:42 PM2/13/14
to bootstrap-...@googlegroups.com
I have 2 date input fields. Lets call them datetimepicker1 and datetimepicker2. If a date is selected in datetimepicker1, the start date of datetimepicker2 should be set to that date. Likewise, if a date is selected in datetimepicker2, the end date of datetimepicker1 should be set to that value.

I have tried to get this to work but to now avail. I tried the following just to set the start date to a hard coded value of 2/11/2014. This did not work, either.

       <script type="text/javascript">
        $(function () {
$('#datetimepicker1').datepicker({
                        todayBtn: "linked",
                        keyboardNavigation: false,
                        todayHighlight: true
    });
          $('#datetimepicker2').datepicker({
                       todayBtn: "linked",
                      keyboardNavigation: false,
                      todayHighlight: true
});
$('#datetimepicker1').datepicker()
                          .on(changeDate, function(e){
    $('#datetimepicker2').datepicker('setStartDate', '2/11/2014');
            });
        });
    </script>

Any idea what I am missing?

Andrew Rowls

unread,
Feb 13, 2014, 2:28:57 PM2/13/14
to A.S., bootstrap-...@googlegroups.com
Your .on is missing quotes around `changeDate`.

This should do what you're looking for:

http://jsfiddle.net/ZQ5pu/1/

<div class="input-daterange">
<input id="datetimepicker1" />
<span class="add-on">to</span>
<input id="datetimepicker2" />
</div>

$('#datetimepicker1').datepicker({
todayBtn: "linked",
keyboardNavigation: false,
todayHighlight: true
});
$('#datetimepicker2').datepicker({
todayBtn: "linked",
keyboardNavigation: false,
todayHighlight: true
});
$('#datetimepicker1')
.on('changeDate', function(e){
$('#datetimepicker2').datepicker('setStartDate', e.date);
});
$('#datetimepicker2')
.on('changeDate', function(e){
$('#datetimepicker1').datepicker('setEndDate', e.date);
});
> --
> You received this message because you are subscribed to the Google Groups "bootstrap-datepicker" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bootstrap-datepi...@googlegroups.com.
> To post to this group, send email to bootstrap-...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bootstrap-datepicker/64d19c85-f6b3-488b-bf44-dd17386ac030%40googlegroups.com.

A.S.

unread,
Feb 13, 2014, 3:11:22 PM2/13/14
to bootstrap-...@googlegroups.com, A.S., and...@eternicode.com
Thank you.


B24

unread,
Apr 6, 2014, 2:17:53 PM4/6/14
to bootstrap-...@googlegroups.com, A.S., and...@eternicode.com
Hi,

My requirements is much the same, and your suggestion works almost perfect.
Basically, I have 2 date range fields - "From" and "To".

My challenge is that the "To" and "From" can not be the same day/date.

So I would need something like this:


$('#datetimepicker1')
     .on('changeDate', function(e){
         $('#datetimepicker2').
datepicker('setStartDate', e.date + one day);
     });
$('#datetimepicker2')
     .on('changeDate', function(e){
         $('#datetimepicker1').datepicker('setEndDate', e.date - one day);
     });


Do you know if this is possible?


Thank you and best regards
Lars
> To unsubscribe from this group and stop receiving emails from it, send an email to bootstrap-datepicker+unsub...@googlegroups.com.

B24

unread,
Apr 15, 2014, 6:46:10 AM4/15/14
to bootstrap-...@googlegroups.com, and...@eternicode.com
Fixed this temporary by changing back to the original datepicker (http://www.eyecon.ro/bootstrap-datepicker/).
This functionallity is in place there by default.

But would appreciate if there is a way to do this here in the future so that we can upgrade to your version.


Best Regards
Lars

Ven Para Orlando

unread,
Apr 28, 2014, 7:43:51 PM4/28/14
to bootstrap-...@googlegroups.com, and...@eternicode.com
How I can change the language for example Spanish ?
Reply all
Reply to author
Forward
0 new messages