自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用sql日期函數(shù)獲得一個月中的天數(shù)

數(shù)據(jù)庫 SQL Server
使用借助sql日期函數(shù),可以獲取給定年份和月份的天數(shù),下面就將為您介紹這種功能的實現(xiàn),希望對您更好學習sql日期函數(shù)有所幫助。

借助sql日期函數(shù),可以實現(xiàn)許多我們想要的功能,下面就將為您介紹使用sql日期函數(shù)獲得一個月中的天數(shù)的方法,供您參考,希望對您學習sql日期函數(shù)能有所啟迪。

--獲取給定年份和月份的天數(shù)

  1. alter function fn_getDayByYearMonth(@year int,@month int)  
  2. returns int  
  3. begin  
  4. declare @date datetime  
  5. declare @day int  
  6. if(@month<>12)  
  7. begin  
  8. set @month = @month + 1  
  9. set @date = cast(cast(@year as varchar)+'-'+cast(@month as varchar)+'-1' as datetime)  
  10. end  
  11. if(@month=12)  
  12. begin  
  13. set @date = cast(cast(@year as varchar)+'-'+cast(@month as varchar)+'-31' as datetime)  
  14. end   
  15. set @dayday = day(@date-1)  
  16. return @day  
  17. end  

--獲取給定年份和月份中***的那一天

  1. alter function fn_getMaxDate(@year int,@month int)  
  2. returns datetime  
  3. begin  
  4. declare @date datetime  
  5. declare @day int  
  6. set @day = dbo.fn_getDayByYearMonth(@year,@month)  
  7. set @date = cast(cast(@year as varchar)+'-'+cast(@month as varchar)+'-'+cast(@day as varchar) as datetime)  
  8. return @date  
  9. end 

 

 

 

【編輯推薦】

初級sql select語法

sql server死鎖的檢測方法

SQL SERVER字段類型的說明

SQL Server安全解析

保護sql server安全的措施

責任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關推薦

2010-07-09 13:10:53

SQL Server日

2010-06-18 13:56:10

SQL Server日

2010-06-28 10:21:42

SQL Server日

2019-04-01 14:17:36

kotlin開發(fā)Java

2012-12-20 10:18:10

Windows 8

2018-01-10 12:09:12

Android開發(fā)程序員

2021-10-28 05:39:14

Windows 10操作系統(tǒng)微軟

2010-09-10 15:32:53

SQL函數(shù)日期格式化

2013-05-27 09:47:33

Java開發(fā)Java跨平臺

2009-11-23 08:52:02

Windows 7首月銷量

2019-10-08 11:07:55

Python 開發(fā)編程語言

2016-01-11 19:38:51

七牛

2025-01-20 08:10:00

AI模型研究

2012-08-31 16:40:24

Mac操作系統(tǒng)

2021-07-20 08:57:26

滴滴上市網(wǎng)絡安全審查

2009-02-16 09:15:49

蘋果喬布斯CEO

2013-08-12 16:35:22

2019-03-11 08:36:00

Office 應用微軟

2012-09-24 10:10:35

打樁機AMDFX-系列
點贊
收藏

51CTO技術棧公眾號