How do I get yesterday's date in the time.Time
struct in Go?
Here's one way with AddDate
:
time.Now().AddDate(0, 0, -1)
The original answer also had a time.Add
suggestion:
fmt.Printf("Yesterday: %v\n", time.Now().Add(-24*time.Hour))
See Vatine's comment for reasons to prefer AddDate
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With