×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang program to print tomorrow's date

Here, we are going to learn how to print tomorrow's date in Golang (Go Language)?
Submitted by Nidhi, on March 22, 2021 [Last updated : March 04, 2023]

Printing tomorrow's date in Golang

Problem Solution:

In this program, we will get today's date using time.Now() function and add 1 day into today's date and print tomorrow's date on the console screen.

Program/Source Code:

The source code to print tomorrow's date is given below. The given program is compiled and executed successfully.

Golang code to print tomorrow's date

// Golang program to print tomorrow's date

package main

import "fmt"
import "time"

func main() {

	today := time.Now()
	tomorrow := today.AddDate(0, 0, 1)

	fmt.Printf("Today    : %02d-%02d-%04d\n", today.Day(), today.Month(), today.Year())
	fmt.Printf("Tomorrow : %02d-%02d-%04d", tomorrow.Day(), tomorrow.Month(), tomorrow.Year())
}

Output:

Today    : 22-03-2021
Tomorrow : 23-03-2021

Explanation:

In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.

In the main() function, we got today's date using the Now() function and add 1 day into today's date using the AddDate() function, and print tomorrow's date on the console screen.

Golang Date & Time Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.