javascript - get start day of week and end day fullCalendar - Stack Overflow

I´m traying to get actual week with fullCalendar plugin in laravel 5.8. I need get it, to send this dat

I´m traying to get actual week with fullCalendar plugin in laravel 5.8. I need get it, to send this date to controller and to do a query with this date.

In my script.js i have a listener click but change my view to week and in this view in title put current week in this format:

8 – 14 mar 2021

i want to get firts day of week and last day of week. Also i´m traying with

var currentDate = calendar
var beginOfWeek = currentDate.startOf('week');
var endOfWeek = currentDate.endOf('week');

but returned me:

currentDate.startOf is not a function

because currentData return empty array... But i´m instaciate my calendar so:

var calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
    headerToolbar: {
        left: 'prev next today',
        center: 'title',
        right: 'dayGridDay dayGridWeek dayGridMonth listMonth'
    },
    locale: config.lang,
    initialView: 'dayGridMonth',
    displayEventTime: true,
    
    events: dbEvents,

and i have all my events from DB in my calendar... I don´t understand why i can´t use my object to use startOf and endOf.

I don´t know i´m doing well my logic, maybe i should to do this to other form. How can i get current week? and even i want show next or last week that i can get this week ok.

Thanks so much for help, and sorry for my english i hope that you can understand me.

I´m traying to get actual week with fullCalendar plugin in laravel 5.8. I need get it, to send this date to controller and to do a query with this date.

In my script.js i have a listener click but change my view to week and in this view in title put current week in this format:

8 – 14 mar 2021

i want to get firts day of week and last day of week. Also i´m traying with

var currentDate = calendar
var beginOfWeek = currentDate.startOf('week');
var endOfWeek = currentDate.endOf('week');

but returned me:

currentDate.startOf is not a function

because currentData return empty array... But i´m instaciate my calendar so:

var calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
    headerToolbar: {
        left: 'prev next today',
        center: 'title',
        right: 'dayGridDay dayGridWeek dayGridMonth listMonth'
    },
    locale: config.lang,
    initialView: 'dayGridMonth',
    displayEventTime: true,
    
    events: dbEvents,

and i have all my events from DB in my calendar... I don´t understand why i can´t use my object to use startOf and endOf.

I don´t know i´m doing well my logic, maybe i should to do this to other form. How can i get current week? and even i want show next or last week that i can get this week ok.

Thanks so much for help, and sorry for my english i hope that you can understand me.

Share Improve this question edited Mar 11, 2021 at 8:29 ADyson 62.2k16 gold badges79 silver badges92 bronze badges asked Mar 11, 2021 at 7:56 scorpions78scorpions78 5586 silver badges27 bronze badges 3
  • As per fullcalendar.io/docs#toc, fullCalendar does not have a startOf or endOf week. I'm not sure what you were trying to do there, or what you were expecting to happen, or why? You could try calendar.view.activeStart and calendar.view.activeEnd instead - see fullcalendar.io/docs/view-object – ADyson Commented Mar 11, 2021 at 8:28
  • However, I would actually remend that you read fullcalendar.io/docs/events-json-feed so that you can define a dynamic event source, and have fullCalendar refresh the events automatically whenever the view or the date changes. It will automatically send the correct start and end dates to your server so that your server can return the required events correctly. And you don't have to worry about getting those dates yourself, or triggering the refresh. If you wanted to trigger a refresh from your own code though, you'd run fullcalendar.io/docs/Calendar-refetchEvents. – ADyson Commented Mar 11, 2021 at 8:31
  • @ADyson thanks for your response, just i need this!!! thanks – scorpions78 Commented Mar 11, 2021 at 8:38
Add a ment  | 

2 Answers 2

Reset to default 5

with this function, i´m able to get week´s days

/** GET DAYS OF WEEK */
  function getDaysOfWeek(calendar){
    if(!calendar) return;
    let startDayWeek = calendar.view.activeStart;
    let endDayWeek = calendar.view.activeEnd;

    var firstDay = new Date(startDayWeek);
    var lastDay = new Date(endDayWeek);

    dayStartWeek = firstDay.toISOString().substring(0,10);
    dayEndWeek = lastDay.toISOString().substring(0,10);
  }

I made like this because some end month wasn´t works properly:

function getDaysOfWeek(){
    var calendar = calendarRef.current.getApi();
    let startDayWeek = calendar.view.currentStart;
    let endDayWeek = calendar.view.currentEnd;
    var firstDay = new Date(startDayWeek);
    var lastDay = new Date(endDayWeek);
    firstDay.setDate(firstDay.getDate() + 1);
    lastDay.setDate(lastDay.getDate() - 2);
console.log(firstDay.toISOString().substring(0,10),lastDay.toISOString().substring(0,10));
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745252920a4618784.html

相关推荐

  • javascript - get start day of week and end day fullCalendar - Stack Overflow

    I´m traying to get actual week with fullCalendar plugin in laravel 5.8. I need get it, to send this dat

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信