根據日期獲取當月有幾天

2021-04-17 12:59:14 字數 718 閱讀 2247

--根據日期獲取當月有幾天

declare @date  varchar(10)  --某日期

declare @newdate varchar(10)  --下月的第一天

declare @month  int    --當月月數

declare @day  int    --天數

declare @year  int    --當年年數

set @date = convert(char,getdate(),120)  --設定日期為當天(測試用)

set @day = datepart(day,@date)    --獲取當天是本月的第幾天

set @year = datepart(year,@date)   --獲取當年年數

set @month = datepart(month,@date)   --獲取當月月數

--獲取下月月數

set @month = @month + 1

--獲取下月的第一天的日期

set @newdate = cast(@year as varchar) + '-' + cast(@month as varchar) + '-1'

--當月天數 = 本日期所處當月天數 + 下月第一天日期與本日期之間的差值 - 1

set @day = @day + datediff(day,@date,@newdate) - 1

select @day

ORACLE根據日期獲取當月的天數

create or replace function get days p date date return number authid current user asp days number 0 begin select to date to char add months p date,1 y...

04 根據日期計算當月天數

需求 給出日期,求出其當月份的天數 我們需要用到eomonth函式和day函式,在此解釋一下這兩個函式 eomonth函式 語法 eomonth start date,months 作用 返回一串日期,表示指定月數之前或者之後的月份的最後一天 舉例 當單元格a1內容為 1月1日 輸入公式 eomon...

根據給定日期生成當月日期列表sql語句

下面是本人在開發過程中遇到的乙個問題,需要根據給定的日期 生成當月的日期列表,用於生成當月的報表資料,為了提高系統效率,索性將生成日期列表的操作放在了sql中完成,生成方法借助了mysql資料庫自帶的一張表mysql.help.topic,原因是該錶的記錄數足夠我們用來生成列表,但是我並沒有使用my...