mysql 周轉日期 指定周轉對應日期

2021-10-17 20:13:13 字數 1193 閱讀 6680

sql 根據某年某周獲取對應日期

--建立乙個標量值函式

--例:weektoday(2018,18)

create function [dbo].[weektoday](@year int,@week int)

returns varchar(50)

asbegin

declare @year1 datetime

declare @stratweek datetime

declare @endweek datetime

set @year1=convert(smalldatetime,convert(varchar(4),@year) + '-1-1')

set @stratweek=dateadd(day,1-datepart(weekday,@year1),dateadd(week,@week-1,@year1))

set @endweek=dateadd(day,6,@stratweek)

return convert(varchar(10),@stratweek,111)

endc#  根據某年某周獲取對應日期

例:  getfirstdayofweek(year, week, system.globalization.cultureinfo.invariantculture);

/// 根據一年中的第幾周獲取該週的開始日期

public static datetime getfirstdayofweek(int year, int week, system.globalization.cultureinfo culture)

system.globalization.calendar calendar = culture.calendar;

datetime firstofyear = new datetime(year, 1, 1, calendar);

datetime targetday = calendar.addweeks(firstofyear, week - 1);

dayofweek firstdayofweek = culture.datetimeformat.firstdayofweek;

while (targetday.dayofweek != firstdayofweek)

targetday = targetday.adddays(-1);

return targetday;

一年某一周轉換成具體日期

using system class program3 int i console.write 年 year int.parse console.readline console.write 周次 week int.parse console.readline if year 0 if week 1...

mysql指定日期加

mysql時間加減函式為date add date sub 定義和用法 date add 函式向日期新增指定的時間間隔。date sub 函式向日期減少指定的時間間隔。語法date add date,interval expr type date sub date,interval expr typ...

mysql 固定日期 mysql查詢指定日期

1.今天 select from hb contract in h where to days modify date to days now 2.昨天 select from hb contract in h where to days now to days modify date 1 3.近七...