zoukankan      html  css  js  c++  java
  • 知道周求时间范围

     
    SET DATEFIRST 1

    declare @strTime nvarchar(50);
    set @strTime='week8'; --8月

    declare @CurYear int;
    select @CurYear=datepart(year,GETDATE());
    declare @dateFirstDayOfYear datetime; --年的第一天
    declare @dateFirstDayOfWeek datetime;--周的第一天
    declare  @dateLastDayOfWeek datetime;--周的最后一天
    declare @whichtime nvarchar(50); --月或周的数量
    declare @startTime datetime; --月的第一天
    declare @EndTime datetime; --月的最后一天
    declare @Monthlocation int; --月字段的位置
    declare @WeekLocation int; --周字段的位置
    set @Monthlocation=charindex('月',@strTime);
    set @WeekLocation=charindex('week',@strTime);
    --求月时间范围
    if(@Monthlocation>0)
    begin
     set @whichtime=replace(@strTime,'月','');
     set @startTime=cast((cast(@CurYear as varchar(4))+'-'+@whichtime+'-1') as datetime);
     set @EndTime=dateadd(day,-1,dateadd(month,1,@startTime));
     
     select @startTime,@EndTime;
    end

    --求周时间范围
    if(@WeekLocation>0)
    begin
     set @whichtime=replace(@strTime,'week','');
     set @dateFirstDayOfYear=cast((cast(@CurYear as varchar(4))+'-1-1') as datetime);
     set @dateFirstDayOfWeek=dateadd(day,1-datePart(weekday,@dateFirstDayOfYear),dateAdd(week,@whichtime-1,@dateFirstDayOfYear));
     set @dateLastDayOfWeek=dateadd(day,6,@dateFirstDayOfWeek);
        select @dateFirstDayOfWeek,@dateLastDayOfWeek;
    end

  • 相关阅读:
    Poj 2391 二分答案+最大流+拆点
    POJ 1087 A Plug for UNIX 最大流
    POJ 1459 Power Network 最大流
    POJ 2112 Optimal Milking 二分答案+最大流
    POJ 1273 Drainage Ditches 最大流
    POJ 1149 PIGS 最大流
    POJ 2288 Islands and Bridges 哈密尔顿路 状态压缩DP
    The Cow Lexicon
    1523. K-inversions
    1350. Canteen
  • 原文地址:https://www.cnblogs.com/lgxll/p/2674596.html
Copyright © 2011-2022 走看看