go - Compare only date part ot time.Time in Golang -
assume following 2 dates. date same, time different.
t1, _ := time.parse("2006-01-02 15:04:05", "2016-01-01 12:12:12.0") t2, _ := time.parse("2006-01-02 15:04:05", "2016-01-01 18:19:20.0")
i compare them using format()
, not sure if that's best way, when different timezones @ play.
if t1.format("2006-01-02") == t2.format("2006-01-02") { // dates equal, don't care time. }
is approach, or missing something?
you can either truncate time day:
t1.truncate(24*time.hour).equal(t2.truncate(24*time.hour))
or can compare year , day separately:
t1.year() == t2.year() && t1.yearday() == t2.yearday()
Comments
Post a Comment