This article introduces the program code used in c #, vb.net, and SQL to determine whether the specified date is a leap year. If you need it, refer to this article.
The Code is as follows: |
Copy code |
Public bool IsLeapYear (int year) { If (year <1) | (year> 9999 )) { Throw new ArgumentOutOfRangeException ("year", "the year must be a number from 1 to 9999 ."); } If (year % 4 )! = 0) { Return false; } If (year % 100) = 0) { Return (year % 400) = 0 ); } Return true; } |
VB. NET:
The Code is as follows: |
Copy code |
Public Function IsLeapYear (year As Integer) As Boolean If (year <1) OrElse (year> 9999) Then Throw New ArgumentOutOfRangeException ("year", "the year must be a number between 1 and 9999 .") End If If (year Mod 4) <> 0 Then Return False End If If (year Mod 100) = 0 Then Return (year Mod 400) = 0) End If Return True End Function |
SQL
The Code is as follows: |
Copy code |
Udf_DaysInMonth_Ver2 Create function [dbo]. [udf_DaysInMonth] ( @ Date DATETIME ) RETURNS INT AS BEGIN Return case when month (@ Date) IN (1, 3, 5, 7, 8, 10, 12) THEN 31 When month (@ Date) IN (4, 6, 9, 11) THEN 30 Else case when (YEAR (@ Date) % 4 = 0 and year (@ Date) % 100 <> 0) OR (YEAR (@ Date) % 400 = 0) THEN 29 ELSE 28 END END END
|
In this way, I will write all three instances in the form of code.