Alan392
Alan392

Reputation: 685

Full Calendar - How get year and month after click on prev or next button?

I use Full Calendar in my project and I need to get year and month when I click on Prev or Next button.

This is my code, but doesn't work !! It return alway the current date.

            $('body').on('click', 'button.fc-prev-button', function () {
                var tglCurrent = $('#calendar').fullCalendar('getDate');
                var year = moment(tglCurrent).format('YYYY');
                var month = moment(tglCurrent).format('MM');
                alert('Year is '+year+' Month is '+month);
            });

            $('body').on('click', 'button.fc-next-button', function () {
                var tglCurrent = $('#calendar').fullCalendar('getDate');
                var year = moment(tglCurrent).format('YYYY');
                var month = moment(tglCurrent).format('MM');
                alert('Year is ' + year + ' Month is ' + month);
            });

How can I resolve this issue ?

Upvotes: 2

Views: 3830

Answers (1)

karun
karun

Reputation: 66

Try to do it in below way

$('body').on('click', 'button.fc-prev-button', function () {
                var tglCurrent = $('#calendar').fullCalendar('getDate');
                var date = new Date(tglCurrent);
                var year = date.getYear();
                var month = date.getMonth();
                alert('Year is '+year+' Month is '+month);
            });

           

Upvotes: 3

Related Questions