0
  1. I have a month start date and end date,(2020-09-01) and (2020-09-30)
  2. i need to convert into week1 start date and week1 end date.
  3. assume week = Monday to Saturday
  4. like wise i need all weeks for a month
  5. Thanks in advance
Amit Dar
  • 43
  • 4
abhi
  • 21
  • 5
  • Can you show us what you have tried so far? – Phobos Sep 16 '20 at 05:21
  • First Week 2020-09-01 To 2020-09-07 Second Week 2020-09-08 To 2020-09-14 Third Week 2020-09-15 To 2020-09-21 Fourth Week 2020-09-22 To 2020-09-28 Fifth Week 2020-09-29 To 2020-09-30 – abhi Sep 16 '20 at 05:23
  • i have added 7 days for 1st date, – abhi Sep 16 '20 at 05:24
  • You say weeks are Monday to Sunday, but then define the weeks of the month as starting on Tuesday (because 1 Sep 2020 is a Tuesday). You should put additional information in the question, not in comments. Your list of week days is very important as it answers a number of questions. – RobG Sep 16 '20 at 09:26

1 Answers1

0

You can use getDay() to get the day of the week. Then use it as an offset to get the first week.

var date1 = new Date('September 1, 2020 03:24:00')
var nextMonday = new Date(date1.getTime()+1000*60*60*24*(8-date1.getDay()))
Eriks Klotins
  • 4,042
  • 1
  • 12
  • 26
  • `new Date('September 1, 2020 03:24:00')` is not a good way to create a date, `new Date(2020, 8, 1, 3, 24)` is much preferred. Not all days are 24 hours long where daylight saving is observed, so adding a day (or any number of days) should be done as for [this answer](https://stackoverflow.com/a/9989458/257182). – RobG Sep 16 '20 at 09:20