Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullcalendar select wrong end date

I am using selectable function where when user select a date, it will shows the start and end date in a modal. but the the end date showed is extra one day from the actual selected date. for example, of i click on 1st march, the end date will showed 2nd march. here is my code:

select: function (start, end, allDay, jsEvent, view) {
          var view = $('#calendar').fullCalendar('getView');
          $("#EndDate").val('');
          alert(end);

          if (view.name === "month") {
            $('#DateForm').modal('show');
            $("#EndDate").val(start.format('ddd, DD-MMM-YYYY, hh:mm a'));
          } else {
          }
        }
like image 543
yusry Avatar asked Oct 16 '22 21:10

yusry


People also ask

How do I change the date on FullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

How do I start and end date in FullCalendar?

We can get start date by getView event with intervalStart. We can get end date by getView event with intervalEnd. var month = $('#calendar'). fullCalendar('getView').

How do I select multiple dates in FullCalendar?

Detect when the user clicks on dates or times. Give the user the ability to select multiple dates or time slots with their mouse or touch device. Allows a user to highlight multiple days or timeslots by clicking and dragging.

How do I turn off date in FullCalendar?

for disable cell on click (version 2.0) : dayRender: function( date, cell ) { // It's an example, do your own test here if(cell. hasClass("fc-other-month")) { cell. addClass('disabled'); } }, dayClick: function(date, jsEvent, view) { if($(jsEvent.


2 Answers

What you're seeing is the correct, documented behaviour. The documentation of the "end" property of an event states:

The exclusive date/time an event ends. [...] It is the moment immediately after the event has ended. For example, if the last full day of an event is Thursday, the exclusive end of the event will be 00:00:00 on Friday!

See https://fullcalendar.io/docs/event-object for more.


P.S. the line var view = $('#calendar').fullCalendar('getView'); in your code above is redundant - you already have access to the view via the parameter of the same name in your callback. You can remove this line and the code will continue to work.

like image 114
ADyson Avatar answered Oct 21 '22 04:10

ADyson


You can do this in this way

      select: function (start, end, allDay, jsEvent, view) {
      var endDate = new Date(end);
      beforeDay = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate() - 1);
      $("#EndDate").val(beforeDay.format('ddd, DD-MMM-YYYY, hh:mm a'));
     }     
like image 34
Mehran Mazhar Avatar answered Oct 21 '22 04:10

Mehran Mazhar