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.
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
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
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.
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.🔥153 Views