none
How to use datediff to count difference between two dates

Answers

  • >>>>May i know how to SUM Day in between Start_day and End_day ?

    SELECT DATEDIFF(d,Start_day,End_day)

    If it does not help please please post a desired result.


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

    Friday, September 20, 2013 3:40 AM
    Answerer
  • Yss, i get the result



    SELECT  COUNT(LeaveDAYS) FROM
    (
    SELECT 
        DATEDIFF (day,convert(varchar(8),EMPLEAVE.START_DAY,112), CONVERT (varchar(8),EMPLEAVE.END_DAY,112)) AS Days
    FROM
      AcmkIMS.DBO.EP_EMP_INFO EMPINFO JOIN  ACMKPTMS.DBO.ACMKPTMS_LEAVE EMPLEAVE
      
       ON EMPINFO.EP_EMP_ID COLLATE DATABASE_DEFAULT = EMPLEAVE.EMP_NO  COLLATE DATABASE_DEFAULT
       
       WHERE 1=1
       
       AND  CONVERT(varchar(8),getdate(),112) between convert(varchar(8),EMPLEAVE.START_DAY,112) 
                AND CONVERT (varchar(8),EMPLEAVE.END_DAY,112)
                                    
     )DAYS  
                                
    GROUP BY LeaveDAYS
    Friday, September 20, 2013 7:13 AM

All replies