How to get days (dp.days) according to start date and end date from user selected

Asked by MoonStar
10 years ago.

How can i get dp.days when user selected start date and end date from calendar??
I want to display in daypilot scheduler according to user selected start date and end date !!

Comment posted by MoonStar
10 years ago.

Dear Dan Letecky,
Thanks for your reply. But it's still not working.I added my code details in the following.
Please , have a look at the code and reply if u have time.

Firstly, i write the following in script .
<script type="text/javascript">
var picker1 = new DayPilot.DatePicker({
target : 'start',
pattern : 'MMM dd/yyyy',
onTimeRangeSelected : function(args) {
dp.startDate = args.start;
dp.update();
}
});

var picker2 = new DayPilot.DatePicker({
target : 'end',
pattern : 'MMM dd/yyyy',
onTimeRangeSelected : function(args) {
dp.endDate = args.end;
dp.update();
}
});
</script>

Second, i write this in table.
<tr>
<td><input type="text" id="start" />
<a href="#" onclick="picker1.show(); return false;"><img src="images/calendar.png" /></a></td>
</tr>
<tr>
<td><input type="text" id="end" />
<a href="#" onclick="picker2.show(); return false;"><img src="images/calendar.png" /></a></td>
</tr>

Finally,
<script type="text/javascript">
var idArray = [];

var dp = new DayPilot.Scheduler("dp");
dp.startDate = new DayPilot.Date();
dp.endDate=new DayPilot.Date();
dp.businessBeginsHour = 8;
dp.businessEndsHour = 18;
dp.showNonBusiness = false;

dp.days = DayPilot.DateUtil.daysDiff(dp.startDate, dp.endDate);
//i write this, but it doesn't work

Comment posted by MoonStar
10 years ago.

Please reply as early as you can.Thanks a lot .

Answer posted by Dan Letecky [DayPilot]
10 years ago.

You need to update .days in the DayPilot.DatePicker.onTimeRangeSelected event handler like this:

<script type="text/javascript">

 var picker1 = new DayPilot.DatePicker({
  target : 'start',
  pattern : 'MMM dd/yyyy',
  onTimeRangeSelected : function(args) {
   dp.startDate = picker1.date;
   dp.days = DayPilot.DateUtil.daysDiff(picker1.date, picker2.date);
   dp.update();
  }
 });

var picker2 = new DayPilot.DatePicker({
  target : 'end',
  pattern : 'MMM dd/yyyy',
  onTimeRangeSelected : function(args) {
   dp.startDate = picker1.date;
   dp.days = DayPilot.DateUtil.daysDiff(picker1.date, picker2.date);
   dp.update();
  }
 });

</script>

Let me know if it didn't help.

Comment posted by MoonStar
10 years ago.

Hello Dan,

Thank you very much for your reply.It's very useful to me.
Now, I can solve my problem using your advice.
That's great!!!!!

Comment posted by Dan Letecky [DayPilot]
10 years ago.

Great, thanks for the update!

This question is more than 1 month old and has been closed. Please create a new question if you have anything to add.