Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Calendar get date from selected Week

I'm using FullCalendar plugin(week view) for jQuery in my project. In FullCalendar week view, I can see a row showing the date in following format:- Sunday 9/6, Monday 9/7, Tuesday 9/8 so on...

var calendar = $('#calendar').fullCalendar({
    header: {
        left: 'prev',
        center: 'title',
        right: 'next'
    },
    defaultView: 'basicWeek'                    
});

Now I have used only header format in calendar for time sheet project. I want to get dates 9/6, 9/7 from current selected week in alert when move to next/previous week (this is for store date in database). It is possible to get dates separately for current week?

like image 242
KaviSuja Avatar asked Jul 01 '15 09:07

KaviSuja


People also ask

How do I get fullCalendar day?

Calendar::getDate Returns a Date for the current date of the calendar. For month view, it will always be some time between the first and last day of the month. For week views, it will always be sometime between the first and last day of the week.

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').


1 Answers

You can get the begin & end dates from fullcalendar like this:

let currentDate = $('#calendar').fullCalendar('getDate');
let beginOfWeek = currentDate.startOf('week');
let endOfWeek = currentDate.endOf('week');

Edit:

You can add the events configuration for fullcalendar. This way you will get the start & end dates when switching views and it also lets you fetch events and render them on the calendar.

events: function(start, end, callback) {
  // request the back-end and call the callback when the ajax is done
  $.get('events/get', function(result) {
    callback(result);
  });
}
like image 50
A1rPun Avatar answered Sep 23 '22 16:09

A1rPun