Here, we used the function Format(), which is used to get the date and time formatted based on the style argument.
Return Value :
The Format() function returns the time of the formatted date as a string.
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
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.