KAJAL NANAWARE
KAJAL NANAWARE

Reputation: 11

fullcalendar get current month start and end date react example

What is alternative solution for below piece of code if I wanted to write use this in React js or simple Javascript ? var startDate = $('#calendar').fullCalendar('getView').intervalStart.format('DD/MM/YYYY'); var endDate = $('#calendar').fullCalendar('getView').intervalEnd.format('DD/MM/YYYY');

Upvotes: 1

Views: 5756

Answers (3)

Jheysson Urbano
Jheysson Urbano

Reputation: 107

Get current month where January = 1, December = 12

const getCurrentMonth = (arg)  => {
    const startDate = arg.view.activeStart
    if (arg.view.type === 'dayGridMonth'){
        console.log('Current Month', startDate.getMonth() + 1 )
        return
    }
    if( arg.view.type === 'dayGridDay'){
        startDate.setDate(startDate.getDate() + 8)
        console.log('Current Month', startDate.getMonth() + 1 )
    }
}

<FullCalendar
    datesRender={(arg) => getCurrentMonth(arg)}
/>

Upvotes: -2

Raja Faizan
Raja Faizan

Reputation: 73

Hope its working

 <FullCalendar
    datesSet={(arg) => {
      console.log(arg.start) //starting visible date
      console.log(arg.end) //ending visible date
    }}
  />

Upvotes: 4

Arif Hossain
Arif Hossain

Reputation: 21

you can use datesRender props to get the active month range.

 <FullCalendar
    datesRender={(arg) => {
      console.log(arg.view.activeStart) //starting visible date
      console.log(arg.view.activeEnd) //ending visible date
    }}
  />

Upvotes: 1

Related Questions