Skip to content

Instantly share code, notes, and snippets.

@franklinsales
Created April 14, 2017 19:29
Show Gist options
  • Save franklinsales/1df47a38a119a162292b80baa9eeb1df to your computer and use it in GitHub Desktop.
Save franklinsales/1df47a38a119a162292b80baa9eeb1df to your computer and use it in GitHub Desktop.
Just a test in Go to calculate the diff between dates
package main
import (
"fmt"
"time"
)
func main() {
datetimeFormat := "2006-01-02 15:04:05"
today, _ := time.Parse(datetimeFormat, "2017-04-16 23:00:00")
fmt.Printf("%v\n", today)
tomorrow, _ := time.Parse(datetimeFormat, "2017-04-17 00:00:00")
fmt.Printf("%v\n\n", tomorrow)
diff := today.Sub(tomorrow)
fmt.Printf("%v\n", diff)
fmt.Printf("%v\n", int(diff.Hours()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment