Reputation: 831
How do I get yesterday's date in the time.Time struct in Go?
time.Time
Upvotes: 76
Views: 65439
Reputation: 182629
Here's one way with AddDate:
AddDate
time.Now().AddDate(0, 0, -1)
The original answer also had a time.Add suggestion:
time.Add
fmt.Printf("Yesterday: %v\n", time.Now().Add(-24*time.Hour))
See Vatine's comment for reasons to prefer AddDate.
Upvotes: 172