C#、vb.net及SQL判断指定年份是否为闰年的方法
作者:shichen2014 时间:2023-05-18 09:49:55
本文实例讲述了本文章介绍了在c#,vb.net,sql中来判断指定日期是否为闰年的方法。分享给大家供大家参考。具体实现方法如下:
C#代码如下:
public bool IsLeapYear(int year)
{
if ((year < 1) || (year > 9999))
{
throw new ArgumentOutOfRangeException("year", "年份必须是从1至9999之间数字.");
}
if ((year % 4) != 0)
{
return false;
}
if ((year % 100) == 0)
{
return ((year % 400) == 0);
}
return true;
}
VB.NET:
Public Function IsLeapYear(year As Integer) As Boolean
If (year < 1) OrElse (year > 9999) Then
Throw New ArgumentOutOfRangeException("year", "年份必须是从1至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代码如下:
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
这样我就就把三个实例都以代码形式直接写出来了。
希望本文所述对大家的C#、VB.NET及SQL程序设计有所帮助。
标签:C#,vb.net,SQL,判断
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java中dart类详细讲解
2022-01-23 13:01:13
Android源码中final关键字的用法及final,finally,finalize的区别
2023-10-11 09:03:43
Spring Boot JPA Repository之existsBy查询方法失效的解决
2023-01-27 18:36:10
Android开发之保存图片到相册的三种方法详解
2022-07-26 04:49:10
File.createTempFile创建临时文件的示例详解
2022-05-03 08:52:41
![](https://img.aspxhome.com/file/2023/8/77448_0s.png)
Android 动画实现几种方案
2022-08-31 02:57:39
java.exe和javaw.exe的区别及使用方法
2022-08-27 10:03:39
![](https://img.aspxhome.com/file/2023/0/113250_0s.png)
Android通过SOCKET下载文件的方法
2023-08-27 01:11:48
Android进阶事件分发机制解决事件冲突
2021-08-22 06:12:34
![](https://img.aspxhome.com/file/2023/7/123367_0s.png)
winform用datagridview制作课程表实例
2023-11-24 06:08:28
![](https://img.aspxhome.com/file/2023/5/87035_0s.jpg)
Spring框架基于注解开发CRUD详解
2021-08-04 03:39:03
![](https://img.aspxhome.com/file/2023/7/111447_0s.jpg)
opencv3/C++ FLANN特征匹配方式
2021-08-19 10:17:47
![](https://img.aspxhome.com/file/2023/7/117777_0s.jpg)
WPF使用WrapPanel实现虚拟化效果
2021-07-04 14:53:53
![](https://img.aspxhome.com/file/2023/8/116518_0s.gif)
C#实现过滤sql特殊字符的方法集合
2022-01-30 23:58:04
Spring请求参数校验功能实例演示
2023-04-26 02:05:53
Java常用类之System类的使用指南
2021-09-20 07:54:46
![](https://img.aspxhome.com/file/2023/0/101770_0s.png)
Java分布式学习之Kafka消息队列
2022-04-10 22:22:47
![](https://img.aspxhome.com/file/2023/5/113505_0s.png)
Mybatis plus通用字段自动填充的示例
2022-10-27 02:05:27
Android模拟实现支付宝蚂蚁森林效果
2023-03-15 05:07:38
![](https://img.aspxhome.com/file/2023/1/105981_0s.png)
Spring-data-redis操作redis cluster的示例代码
2022-12-17 17:04:00