Skip to content

Instantly share code, notes, and snippets.

@iver
Created November 11, 2014 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iver/de71b99d3ad9531c1788 to your computer and use it in GitHub Desktop.
Save iver/de71b99d3ad9531c1788 to your computer and use it in GitHub Desktop.
Year difference between two dates in go
package main
import "fmt"
import "time"
func main() {
birth, _ := time.Parse("2006-01-02", "2000-11-10")
duration := time.Since(birth)
t1 := time.Unix(0,duration.Nanoseconds())
// Remember, Thursday, 1 January 1970 is defined as first unix day
dif := t1.Year() - 1970
fmt.Printf("Years ->%v", dif )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment