i have far count number of days using http://golang.org/pkg/time/ don't know how exclude weekends , count business days
package main import ( "fmt" "time" ) func main() { t := time.now() f := time.date(2015, time.august, 21, 24, 0, 0, 0, time.utc) diff := f.sub(t) // convert diff days days := int(diff.hours() / 24) fmt.printf("days %d\n", days) }
here's simple little solution.
days := 0 { if (t.equal(f)) { return days } if (t.weekday() != 6 && t.weekday() != 7) { days++ } t.add(time.hour*24) } you don't want use original t variable keeping example simple. loop until t equals f, if they're equal return days count. if they're not check make sure it's weekday , increment days count if is. unconditionally add 1 day starting time.
Comments
Post a Comment