Skip to content

Instantly share code, notes, and snippets.

@nidhi-canopas
Last active July 6, 2022 06:59
Show Gist options
  • Select an option

  • Save nidhi-canopas/9d4cd13ca6f596007b9bfc6c14aea806 to your computer and use it in GitHub Desktop.

Select an option

Save nidhi-canopas/9d4cd13ca6f596007b9bfc6c14aea806 to your computer and use it in GitHub Desktop.
// day = Monday(1), Tuesday(2)...Sunday(7)
func FindNoOfDays(day int, start time.Time, end time.Time) int {
totalDays := 0
for start.Before(end) {
if int(start.Weekday()) == day {
totalDays += 1
}
start = AddDays(start, 1)
}
return totalDays
}
/* Find no. of mondays between two dates */
days := FindNoOfDays(1, time.Now(), time.Now().AddDate(0, 0, 26))
fmt.Println("No. of mondays between:", start, " and end:", end, "are: ", days)
// output:
No. of mondays between: 2022-07-01 12:30:20 +0530 IST and end: 2022-07-31 15:00:50 +0530 IST are: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment