$.date.weeks

Weeks method of date helper

This weeks method is a date helper for getting days or dates in one weeks, so this method only have 3 arguments such as year, week number, and date format.

$.date.weeks(2021, 25, 'YYYY-MM-DD')
//=> ['2021-06-20', '2021-06-21', '2021-06-22', '2021-06-23',
// '2021-06-24', '2021-06-25', '2021-06-26']

Or you may want to week number first before doing render those week dates, you need to use day method (without s) and this method only have 3 arguments as well like year, month, and day/date number.

$.date.week(2021, 6, 21) //=> 25

If you want to get all week numbers in one month or one year, you can use one of the methods below.

// To get all week numbers in one month
$.date.weeksInMonth(2022, 1)
//=> ['1', '2', '3', '4', '5']

// There only 52 weeks in one year (so you don't need this)
$.date.weeksInYear(2021) //=> 52

// Or you may want to get a specific week with its first and last date
$.date.weeksOfYear(2021, 26, 'DD')
//=> {
// '1': [ '03', '09' ], '2': [ '10', '16' ], '3': [ '17', '23' ],
// '4': [ '24', '30' ], '5': [ '31', '06' ], '6': [ '07', '13' ],
// '7': [ '14', '20' ], '8': [ '21', '27' ], '9': [ '28', '06' ], 
// '10': [ '07', '13' ], '11': [ '14', '20' ], '12': [ '21', '27' ],
// '13': [ '28', '03' ], '14': [ '04', '10' ], '15': [ '11', '17' ],
// '16': [ '18', '24' ], '17': [ '25', '01' ], '18': [ '02', '08' ],
// '19': [ '09', '15' ], '20': [ '16', '22' ], '21': [ '23', '29' ],
// '22': [ '30', '05' ], '23': [ '06', '12' ], '24': [ '13', '19' ],
// '25': [ '20', '26' ], '26': [ '27', '03' ]
}

Last updated