Skip to content

Instantly share code, notes, and snippets.

@andrw
Created August 1, 2023 19:26
Show Gist options
  • Select an option

  • Save andrw/04d46195c971289f634f14ef8a48dd1f to your computer and use it in GitHub Desktop.

Select an option

Save andrw/04d46195c971289f634f14ef8a48dd1f to your computer and use it in GitHub Desktop.
is first day of month with go time
func isFirstDayOfMonth(someRuntime time.Time) bool {
currentYear, currentMonth, _ := time.Now().Date()
currentLocation := time.Now().Location()
firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
secondOfMonth := firstOfMonth.Add(24* time.Hour) // multiple ways to get here...
// within first day
if someRuntime.After(firstOfMonth) && someRuntime.Before(secondOfMonth) {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment