Topic: datediff for months Jan 1 to Jan 1 giving 13total Posted: 10 Dec 2013 at 11:39am
Hi all.. I am still a newbie....
I am trying to count the total months for my contract lengths.
I have used
datediff('m',({Contract.StartDate}),({Contract.ExpirDate}))+1;
This does count the number of months
However the problem I am running into is When My contract is from Jan 1 2001 - Jan 1 2002, I am getting a count of 13.
Any help would be greatly appreciated...
Thanks,
TK
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Posted: 11 Dec 2013 at 6:49am
the issue is the contract is ending on 1/1/2002...it probably ended at 12/31/2001 23:59:59.999
DateDiff is very literal, in that for the month/day/time frame it will count as 1 any part of span.
so 1/31/01-1/1/02 would also return 13 months.
Just something to be aware of...Sastry's solution is a good general rule, but I would be willing to be that there are a few time frames that will confuse it and return incorrect results as well.
Again, just something to keep in mind for if/when someone complains about the report.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum