How to calculate the date six months from the current date in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "time"
)

// Function to add months to a given date
func AddMonthsToDate(months int, date time.Time) time.Time {
    return date.AddDate(0, months, 0)
}

func main() {
    // Get the current date
    futureDate := AddMonthsToDate(6, time.Now())

    // Print the new date
    fmt.Println("Date six months from now:", futureDate.Format("2006-01-02"))
}


/*
run:

Date six months from now: 2025-12-12

*/

 



answered Jun 12, 2025 by avibootz

Related questions

1 answer 220 views
1 answer 95 views
1 answer 211 views
211 views asked Aug 26, 2020 by avibootz
1 answer 130 views
1 answer 92 views
...