×

VB.Net Programs

VB.Net program to demonstrate the DaysInMonth() method of DateTime class

By Nidhi Last Updated : November 11, 2024

DateTime.DaysInMonth() Method in VB.Net

The DaysInMonth() method is used to get the number of the day in the specified month of the specified year.

Syntax

Function DaysInMonth (ByVal year as Integer, ByVal month as Integer) as Integer

Parameter(s)

  • Year : Specified Year
  • Date2 : Specified month

Return Value

It returns the number of the day in the specified month of the specified year.

VB.Net code to demonstrate the example of DateTime.DaysInMonth() method

The source code to demonstrate the DaysInMonth() method of the DateTime class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate DaysInMonth() method of 
'DateTime class.

Imports System

Module Module1
    Sub Main()
        Dim days As Integer = 0

        days = DateTime.DaysInMonth(2021, 2)

        Console.WriteLine("Number of Days in Feb 2021 are: {0}", days)
    End Sub
End Module

Output

Number of Days in Feb 2021 are: 28
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 an integer variable days initialized with 0, Here, we got the number of days in February month of the year 2021 that is 28. After that, we print the number of days on the console screen.

VB.Net Date & Time Programs »


Comments and Discussions!

Load comments ↻





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