How to get yesterday's date in golang?

GoTime

Go Problem Overview


How do I get yesterday's date in the time.Time struct in Go?

Go Solutions


Solution 1 - Go

Here's one way with AddDate:

time.Now().AddDate(0, 0, -1)

###EDIT

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionsaggaf.arsyadView Question on Stackoverflow
Solution 1 - GocnicutarView Answer on Stackoverflow