none
How to match date with Getdate ? RRS feed

  • Pergunta

  • 大家好, 

      请教 如何 match  DB 的 date with Getdate ?

    比如,  在 的 table 里 有Apply Leave type ,start time and end time . 那么在  Employee work date & scan time 的table 里要怎样  match leave date with Getdate 如果 employee 没来上班.


    sexta-feira, 23 de agosto de 2013 05:45

Respostas

  • 您好,

    您可以使用 DateDiff(day, getdate(), yourdate) = 0 就是當天。

    SELECT DATEDIFF(day, GETDATE(), '2013-08-23 18:00:00');

    還是您要的是區間?

    CREATE TABLE #leave
    (
    empid VARCHAR(10),
    startDate DATETIME,
    endDate DATETIME
    );
    
    INSERT INTO #leave
            ( empid ,
              startDate ,
              endDate
            )
    VALUES  ( '0001' , -- empid - varchar(10)
              '2013-08-23 09:00:00' , -- startDate - datetime
              '2013-08-23 18:00:00'  -- endDate - datetime
            );
    
    
    INSERT INTO #leave
            ( empid ,
              startDate ,
              endDate
            )
    VALUES  ( '0002' , -- empid - varchar(10)
              '2013-08-22 09:00:00' , -- startDate - datetime
              '2013-08-22 18:00:00'  -- endDate - datetime
            );
    
    SELECT * FROM #leave
    WHERE startDate <= GETDATE() AND endDate >= GETDATE()


    亂馬客blog: http://www.dotblogs.com.tw/rainmaker/


    sexta-feira, 23 de agosto de 2013 06:07

Todas as Respostas

  • 您好,

    您可以使用 DateDiff(day, getdate(), yourdate) = 0 就是當天。

    SELECT DATEDIFF(day, GETDATE(), '2013-08-23 18:00:00');

    還是您要的是區間?

    CREATE TABLE #leave
    (
    empid VARCHAR(10),
    startDate DATETIME,
    endDate DATETIME
    );
    
    INSERT INTO #leave
            ( empid ,
              startDate ,
              endDate
            )
    VALUES  ( '0001' , -- empid - varchar(10)
              '2013-08-23 09:00:00' , -- startDate - datetime
              '2013-08-23 18:00:00'  -- endDate - datetime
            );
    
    
    INSERT INTO #leave
            ( empid ,
              startDate ,
              endDate
            )
    VALUES  ( '0002' , -- empid - varchar(10)
              '2013-08-22 09:00:00' , -- startDate - datetime
              '2013-08-22 18:00:00'  -- endDate - datetime
            );
    
    SELECT * FROM #leave
    WHERE startDate <= GETDATE() AND endDate >= GETDATE()


    亂馬客blog: http://www.dotblogs.com.tw/rainmaker/


    sexta-feira, 23 de agosto de 2013 06:07
  • LZ可以把您的问题说清楚一点吗?
    sexta-feira, 23 de agosto de 2013 13:02