Last active
July 6, 2022 06:59
-
-
Save nidhi-canopas/9d4cd13ca6f596007b9bfc6c14aea806 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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