Display total Days in Current Month in VB.NET

This is the Coding to Display total Days in Current Month. This is the simple code written in VB.NET to count total days in current month. This coding is usefull on some cases while developing some projects. So Let’s begin with this sample program.

Example Code:

In the button click event 3 lines of code created. In the first line it stores current date and time in CurrentDateTime variable. Date.DaysinMonth counts number of days in the given month and year.

  • NOW is the property of VB.NET which access current date and time.
  • Use the date data type to store date value.
  • CurrentDateTime.Year takes current year from CurrentDateTime variable.
  • CurrentDateTime.Month takes the current month from CurrentDateTime variable.
  • The integer variable DaysInMonth stores the value of total number of days.
  • In the messagebox it displays the result in the modal box.
  • The output is current system date and time.
Public Class frmtotaldays
 Private Sub btncountdays_Click(sender As Object, e As EventArgs) Handles btncountdays.Click
   Dim CurrentDateTime As Date = Now
   Dim DaysInMonth As Integer = Date.DaysInMonth(CurrentDateTime.Year, CurrentDateTime.Month)
   MessageBox.Show("Total days in August is " & DaysInMonth)
 End Sub
End Class


Screenshot: 

Open Visual Studio. In the File menu Click on New-> Project. In the project select Visual basic -> Windows Forms application. Enter the project name, select the location to store. It will display one form. In this program just we created one button in the form. The message box will appear after clicking the button.

Form Name: frmtotaldays

Button Name: btncountdays

Display total Days in Current Month


Example Source Code:

This source code developed in VB.NET 2012 and it supports almost all versions. Here is the example source code that we did while preparing video tutorial.

download

Video Tutorial:

This video tutorial clearly explains how to write this program.

Thanks for Reading this article. If any doubts kindly post your queries in the comment box.

Anu

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.