VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to find the leap year Posted by keerthi23 on 8 Jan 2007 at 3:30 AM

Report
Re: how to find the leap year Posted by iwilld0it on 8 Jan 2007 at 7:48 AM
This function should do it ...

Private Function IsLeap(ByVal year As Integer) As Boolean
    Return ((year Mod 4 = 0) AndAlso (year Mod 100 <> 0) OrElse (year Mod 400 = 0))
End Function

Report
Re: how to find the leap year Posted by PavlinII on 8 Jan 2007 at 5:42 PM
: This function should do it ...
:
:
: Private Function IsLeap(ByVal year As Integer) As Boolean
:     Return ((year Mod 4 = 0) AndAlso (year Mod 100 <> 0) OrElse (year Mod 400 = 0))
: End Function
: 

:
Hi,
here's another trick
Public Function IsLeapYear(Yr As Integer) As Boolean
Return Date.TryParse(Yr & "-2-29")
End Function

but iwilld0it's solution is better! (Parsing date from string is time-consuming)
Faster than parsing (but with same idea) and slower than IsLeap is
Private Function IsLeapYear(ByVal Yr As Integer) As Boolean
  Return (New Date(Yr, 2, 28)).AddDays(1).Month = 2
End Function


Pavlin II[/size]

Don't take life too seriously anyway you won't escape alive from it!


Report
Re: how to find the leap year Posted by iwilld0it on 10 Jan 2007 at 10:50 AM
Here is a .NET centric way to do it w/out knowing anything about leap years:

Imports System.Globalization
' ...

Private Function IsLeapYear(ByVal yr As Integer) As Boolean
    Return CultureInfo.CurrentCulture.Calendar.IsLeapYear(yr)
End Function


This function is culture (language) aware.

: : This function should do it ...
: :
: :
: : Private Function IsLeap(ByVal year As Integer) As Boolean
: :     Return ((year Mod 4 = 0) AndAlso (year Mod 100 <> 0) OrElse (year Mod 400 = 0))
: : End Function
: : 

: :
: Hi,
: here's another trick
:
Public Function IsLeapYear(Yr As Integer) As Boolean
: Return Date.TryParse(Yr & "-2-29")
: End Function

: but iwilld0it's solution is better! (Parsing date from string is time-consuming)
: Faster than parsing (but with same idea) and slower than IsLeap is
:
Private Function IsLeapYear(ByVal Yr As Integer) As Boolean
:   Return (New Date(Yr, 2, 28)).AddDays(1).Month = 2
: End Function

:
: Pavlin II[/size]
:
: Don't take life too seriously anyway you won't escape alive from it!
:
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.