| Author |
Topic  |
|
|
bashkim_svirca
Starting Member
1 Posts |
Posted - 03/15/2013 : 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 months
select 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
India
47173 Posts |
|
|
UnemployedInOz
Yak Posting Veteran
Australia
52 Posts |
Posted - 03/15/2013 : 23:33:28
|
-- this will work most of the time. declare @Day1 date, @Day2 date
select @Day1 = '2012-03-05', @Day2 = '2013-04-01'
SELECT @Day2 = DateAdd(dd,Day(@day1) * -1,@Day2)
select DATEDIFF(month, @Day1, @Day2) |
Edited by - UnemployedInOz on 03/15/2013 23:39:48 |
 |
|
| |
Topic  |
|