根據年月以及月中周次,獲取該週開始,結束日期

2021-07-02 18:27:08 字數 546 閱讀 2453

注意,是該月中的周次,一周最多有6周。

//獲取周開始日期和結束日期(週日-週六)

public string getweekdate(int yearly, int monthly, string weekly)

//7*周次 - 第一周中上月天數 > 本月天數

if (7 * int32.parse(weekly) - weekofday1 <= daycount)

datetime datestart = dateend.adddays(-6); //周開始日期

daystr = datestart.tostring("yyyy-mm-dd") +" ~ " + dateend.tostring("yyyy-mm-dd");

}catch (exception)

return daystr;

}

呼叫:var resultweekday = getweekdate(2015, 4, 5);//4月第5周

結果:2015-04-26  ~ 2015-05-02

根據年月生成日曆函式

go 建立函式 第一版 dobear 0922 create function fn calendar year int month int returns nvarchar max as begin declare result nvarchar max enter nvarchar 8 sele...

年月周星期計算年月日 C

輸入年 月 第幾周 週幾,輸出對應的 年 月 日。1.2.1.週日到週六 2.周一到週日 這兩種不同的定義可能會導致不同的計算結果。這裡的 放入的是第一種定義的結果,若想改為第二種,需要調整 中的b 和後續 下面所述全部以第一種定義為基礎。二 第幾周 的定義 每週的第一周和最後一周一般不完整,如上圖...

月中第幾周的週幾演算法

計算乙個陽曆日期是哪月哪周周幾,並以指定格式輸出 如 2013年5月12日是5月第二週週日是母親節 2013年6月16日是6月第三週週日是父親節 每年9月第三週周二是國際和平日,輸入2013年9月10日,輸出字串格式 5.2.0 6.3.0 9.3.2 private string 月中周 date...