Find period between two times with golang

Golang time package provides rich time handling functionality.

Duration type represents passed time between two concrete dates.

start := time.Now()
end := time.Now().AddDate(0, 1, 11)
duration := end.Sub(start)
fmt.Printf("Duration between %v and %v is %v", start, end, duration)
result :
> Duration between 2025-02-16 13:01:16.870769 +0100 CET m=+0.000735054 and 2025-03-27 13:01:16.870769 +0100 CET is 936h0m0s

Sub method returns Duration object has period between firs date and second date. if first date is before than second date, result would be negative

Rate Post :
Similar Posts :
Comments :

Message length should be less than 1024 character!