Friday, 25 May 2007

Check For Leap Year in VB.Net

When dealing with dates in VB.NET, it's a good idea not to perform manual checks or calculations, which may be inaccurate depending on the quality of the code. Instead, it's advisable to rely on the functionality of classes provided by .NET.

For instance, if you need to determine if a given year is a leap year, you can use VB.NET's IsLeapYear function. Here's an example of how you can use the function:

Private Sub LeapYearCheck()
Dim bLeapYear AsBoolean
bLeapYear = Date.IsLeapYear(Now.Year)
bLeapYear = Date.IsLeapYear(2004)
End Sub

In the example, we define a Boolean variable, bLeapYear, to hold the result of whether a given year is a leap year. we then set the value of bLeapYear to the IsLeapYear property of the Date class and pass to it the current year, which we obtain using the Year property of the Now class. We show the value of bLeapYear in a MessageBox. The result is False because 2007 is not a leap year. After that,we follow the same steps for 2004, which is a leap year. In that case, MessageBox shows True.

PHP,Java, DHTML, C, C++ and many more languages, for help visit
Programming Fourm


Unknown said...

Hi,Building links with other websites will provide greater visibility for Web Design Cochin. The more popular the website you have your link in the higher chance that your website will be viewed. Thanks......

Kanye Co Jamila said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Online Training from India. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.