go-examples/datediff/main.go

29 lines
522 B
Go
Raw Normal View History

2017-07-08 14:03:35 +00:00
package main
import "fmt"
import "log"
import "os"
import "time"
func main() {
if len(os.Args) != 3 {
log.Fatalln("usage datediff <date1> <date2>")
}
FORMAT := "02/01/2006"
d1, err := time.ParseInLocation(FORMAT, os.Args[1], time.Local)
if err != nil {
log.Fatalln("Invalid date 1", err)
}
d2, err := time.ParseInLocation(FORMAT, os.Args[2], time.Local)
if err != nil {
log.Fatalln("Invalid date 2", err)
}
dur := d2.Sub(d1)
//fmt.Println(dur.String())
fmt.Println(int64(dur / (24 * time.Hour)))
}