Home »
VB.Net »
VB.Net Programs
VB.Net program to print yesterday's date
By Nidhi Last Updated : November 16, 2024
Print yesterday's date in VB.Net
Here, we will get and print yesterday's dates using DateTime and TimeSpan class.
Program/Source Code:
The source code to print yesterday's dates is given below. The given program is compiled and executed successfully.
VB.Net code to print yesterday's date
'VB.NET program to print yesterday's date.
Imports System
Module Module1
Sub Main()
Dim today As DateTime = DateTime.Now
Dim yesterday As DateTime
yesterday = today - New TimeSpan(1, 0, 0, 0)
Console.WriteLine("Yesterday: {0}/{1}/{2}", yesterday.Day, yesterday.Month, yesterday.Year)
End Sub
End Module
Output
Yesterday: 17/1/2021
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.
In the Main() function, we created two objects of the DateTime class. Here, object today is initialized with the current date using DateTime.Now property and then we subtract timespan from the object today and get yesterday's date and print the result on the console screen.
VB.Net Date & Time Programs »