From 8cd3a4517f73d1e80c730bf760082b4cd141d02c Mon Sep 17 00:00:00 2001 From: Meutel Date: Sat, 8 Jul 2017 16:03:35 +0200 Subject: [PATCH] Date diff --- .gitignore | 1 + datediff/main.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 datediff/main.go diff --git a/.gitignore b/.gitignore index 25977dc..1774231 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ my-md5/my-md5 shadir/shadir shadirconcurrent/shadirconcurrent pinger/pinger +datediff/datediff diff --git a/datediff/main.go b/datediff/main.go new file mode 100644 index 0000000..1c51dbf --- /dev/null +++ b/datediff/main.go @@ -0,0 +1,28 @@ +package main + +import "fmt" +import "log" +import "os" +import "time" + +func main() { + if len(os.Args) != 3 { + log.Fatalln("usage datediff ") + } + + 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))) +}