how to Calcullate Two Dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rajasekar09
    New Member
    • Nov 2007
    • 2

    #1

    how to Calcullate Two Dates

    hi am beginner of SQL ,

    i hav some doubt in SQL Query Between Command..

    i want to calculate two dates using between command..

    example of the Query is:

    SELECT LI.EmpId,EOS.Em p_Name,DS.Descr iption,SUM(conv ert(int, DateDiff (Day,'10/03/2007','11/11/2007'))+1)
    as Leave,LS.NoOfLe aves, (LS.NoOfLeaves -SUM((convert(in t, DateDiff (Day,'10/03/2007' , '11/10/2007'))+1)))
    as Balance FROM
    LEAVEINFO LI,EMPLOYEEOFFI CIALSETUP as EOS,DESGSETUP as DS, LEAVESETUP LS
    WHERE(LI.EmpId= EOS.EmpId AND EOS.DESIGCODE=D S.DESGCODE AND DS.DESGCODE='00 7 ' AND EOS.EmpId='E000 2' ) AND
    LS.NOOFLEAVES=( select NoofLeaves From LeaveSetup where EnteredDate=(se lect Max(EnteredDate ) from LeaveSetup as e
    where EnteredDate=e.E nteredDate))
    GROUP BY LS.NOOFLEAVES,L I.EmpId,EOS.Emp _Name,DS.Descri ption
  • gfajardo
    New Member
    • Nov 2007
    • 4

    #2
    Hi
    here any sample for datediff function and adding days
    run all script in query analyzer

    Code:
    declare @date1 datetime
    declare @date2 datetime
    
    set @date1='20070101'
    set @date2=getdate()
    
    --datediff returns an int
    select datediff(day,@date1,@date2)
    
    --adding days to date type variable only
    select  @date1 + 30
    Good luck

    Comment

    Working...