Home >>VB.Net Built-in Functions >VB.Net program to print date and time in 'day, month dd, yyyy' format using Format() function

VB.Net program to print date and time in 'day, month dd, yyyy' format using Format() function

Write a VB.Net program to print date and time in 'day, month dd, yyyy' format using Format() function() function

Here, we used the function Format(), which is used to get the date and time formatted based on the style argument.

Syntax :

Format(Date, StyleArg)

Parameters :

  • Date: Considering the date object.
  • StyleArg: String Argument used to define the date format

Return Value :

The Format() function returns the time of the formatted date as a string.

Program :

Below is the source code for printing date and time in format 'day, month dd, yyyy' using the Format() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim strDate As String
        Dim D As Date
        D = Date.Now
        strDate = Format(D, "Long Date")
        Console.WriteLine(strDate)
    End Sub
End Module
	
Output:
Tuesday, November 24, 2020

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created two variables, strDate and D, in the Main() method. Here, using Date.Now, we have assigned the current date and time to the D object in the Date class.

strDate = Format(D, "Long Date")

In the above code, we used the Format() function, where we passed the date object "D" and the "Long Date" style argument, which returns the date in the format "day, month dd, yyyy" after we printed the formatted date on the console screen.


No Sidebar ads