0

For Example I need date difference for

1.DECLARE @lDFROM DATE = '2016-12-01',@lDTO DATE = '2018-05-31'

Result :

18 noofmnth,
0 nofweek,
0 noofdays

2.DECLARE @lDFROM DATE = '2016-12-31',@lDTO DATE = '2018-05-25'

Result :

17 noofmnth,
3 nofweek,
4 noofdays
Guna
  • 1
  • 6
  • use `DATEDIFF` function – Radim Bača Sep 27 '17 at 07:04
  • 1
    Possible duplicate of [How to compare two dates to find time difference in SQL Server 2005, date manipulation](https://stackoverflow.com/questions/9521434/how-to-compare-two-dates-to-find-time-difference-in-sql-server-2005-date-manipu) – Umut D. Sep 27 '17 at 07:20

1 Answers1

0

use datediff

select DATEDIFF(wk,'2016-12-01','2018-05-31')+1
Mr. Bhosale
  • 3,018
  • 1
  • 17
  • 34
  • I have tried like this..but cant get exact answer,SELECT DATEDIFF(mm,@lDFROM,@lDTO) noofmnth, DATEDIFF(WW,DATEADD(mm,DATEDIFF(mm,@lDFROM,@lDTO),@lDFROM),@lDTO) nofweek, DATEDIFF(DD,DATEADD(WW,DATEDIFF(WW,DATEADD(mm,DATEDIFF(mm,@lDFROM,@lDTO),@lDFROM),@lDTO), DATEADD(mm,DATEDIFF(mm,@lDFROM,@lDTO),@lDFROM)),@lDTO) + 1 noofdays – Guna Sep 27 '17 at 07:21