VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

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