I'm calculating date difference in golang, I have written code and it is executing fine but when i take the difference of time in minutes, convert the same to integer and comparing in if condition.
code which im trying
as per the below condition, it should not print "diffinmin is greater P" but it is printing. Where im doing wrong?
package main
import (
"fmt"
"time"
"strconv"
)
func main() {
//fetching current time
currentTime := time.Now()
loc := currentTime.Location()
//past time comes in as string
pasttimestr := "2018-10-18 01:00"
layout := "2006-01-02 15:04"
//converting string to date
pasttime, err := time.ParseInLocation(layout, pasttimestr, loc)
if err != nil {
fmt.Println(err)
}
fmt.Println("Past Time: ", pasttime)
fmt.Println("Current Time: ", currentTime)
//differnce between pastdate and current date
diff := currentTime.Sub(pasttime)
var diffinmin int = int(diff.Minutes())
fmt.Printf( "heloo",diffinmin )
fmt.Printf("time difference is %v or %v in minutes
", diff, diff.Minutes())
var strconfigtime = "9000"
var mininttimeconfig int
if mininttimeconfig, err := strconv.Atoi(strconfigtime); err == nil {
fmt.Printf("i=%d, type: %T
", mininttimeconfig, mininttimeconfig)
}
if diffinmin > mininttimeconfig {
fmt.Printf("diffinmin is greater" )
}
}