Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bashkim_svirca
Starting Member
1 Post |
Posted - 2013-03-15 : 12:56:07
|
Can someone help me with this issue. I am using the below queries to get full month between two dates, but I am not getting it with the below queries as in both cases are not showing same value of months which should have been 13. select DATEDIFF(month, '2012-03-05', '2013-04-01')from test1 where contract_no = 1023 - with this query I am getting 13 monthsselect DATEDIFF(month, '2012-03-05', '2013-03-28')from test1 where contract_no = 1023 - with this query I am getting 12 months |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
UnemployedInOz
Yak Posting Veteran
54 Posts |
Posted - 2013-03-15 : 23:33:28
|
-- this will work most of the time.declare @Day1 date, @Day2 dateselect @Day1 = '2012-03-05', @Day2 = '2013-04-01'SELECT @Day2 = DateAdd(dd,Day(@day1) * -1,@Day2)select DATEDIFF(month, @Day1, @Day2) |
|
|
|
|
|