Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to add a number of days (actually a number of weeks) to an existing date in Go. I have tried myDate.Add(time.Hour * 24 * 7 * weeksToAdd)

But I get an error when I try to build: invalid operation: time.Hour * startAdd (mismatched types time.Duration and float64)

So weeksToAdd is currently a float64, but I can change it to an int or whatever. Changing it to an int only changed my error to say that int and Duration can't be multiplied.

How do I add days to a date?

question from:https://stackoverflow.com/questions/32998110/add-days-to-date-in-go

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use Time.AddDate():

myDate.AddDate(0, 0, 7 * weeksToAdd)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...