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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -