Date diff

This commit is contained in:
Meutel 2017-07-08 16:03:35 +02:00
parent 01518f6f9f
commit 8cd3a4517f
2 changed files with 29 additions and 0 deletions

1
.gitignore vendored
View File

@ -39,3 +39,4 @@ my-md5/my-md5
shadir/shadir shadir/shadir
shadirconcurrent/shadirconcurrent shadirconcurrent/shadirconcurrent
pinger/pinger pinger/pinger
datediff/datediff

28
datediff/main.go Normal file
View File

@ -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 <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)))
}