search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

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

Asked by MoonStar
7 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 !!

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

You can use DayPilot.DateUtil.daysDiff() helper method:

DayPilot.DateUtil.daysDiff("2016-06-09", "2016-06-10");

The arguments can be passed as strings (they will be parsed using DayPilot.Date constructor - https://api.daypilot.org/daypilot-date-constructor/) or as DayPilot.Date objects (https://api.daypilot.org/daypilot-date-class/).

Comment posted by MoonStar
7 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
7 years ago.

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

Answer posted by Dan Letecky [DayPilot]
7 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
7 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]
7 years ago.

Great, thanks for the update!

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