Skip to content

Instantly share code, notes, and snippets.

@nidhi-canopas
Last active July 1, 2022 18:50
Show Gist options
  • Select an option

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

Select an option

Save nidhi-canopas/b8a85bf9f800859edc7e7a7f79e98659 to your computer and use it in GitHub Desktop.
func DiffInDays(start time.Time, end time.Time) int {
return int(end.Sub(start).Hours() / 24)
}
/* difference between two timestamps */
func main() {
location, _ := time.LoadLocation("Asia/Kolkata")
start := time.Date(2022, time.July, 01, 12, 30, 20, 0, location)
end := time.Date(2022, time.July, 31, 15, 0, 50, 0, location)
fmt.Println("Days between start and end: ", DiffInDays(start, end))
}
//output:
Days between start and end: 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment