metropia
asked on
get the number of months between start and end dates
Hello.
I have to calculated fields:
I need to add a third calculated field:
The third field is the number of months between [Contract_NetStartDate] and [Contract_NetEndDate]
Is it possible that some one show me how to obtain that number from the two fields?
Thank you much.
I have to calculated fields:
,[Contract_NetStartDate] = CASE WHEN ContractStartDate <= @ReportStartDate THEN @ReportStartDate ELSE ContractStartDate END
,[Contract_NetEndDate] = CASE WHEN ContractEndDate >= @ReportEndDate THEN @ReportEndDate ELSE ContractEndDate END
I need to add a third calculated field:
[Contract_NetNumberOfPeriods]
The third field is the number of months between [Contract_NetStartDate] and [Contract_NetEndDate]
Is it possible that some one show me how to obtain that number from the two fields?
Thank you much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I wouldn't repeat the expressions twice, too hard to keep in sync later.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you experts.
I have a question, why when I use:
DATEDIFF(m,Contract_NetSta rtDate , Contract_NetEndDate)
I get negative numbers, but if I switch to:
DATEDIFF(m, Contract_NetEndDate, Contract_NetStartDate)
Then the number of months is positive
??
I have a question, why when I use:
DATEDIFF(m,Contract_NetSta
I get negative numbers, but if I switch to:
DATEDIFF(m, Contract_NetEndDate, Contract_NetStartDate)
Then the number of months is positive
??
Because your Contract_NetEndDate must be earlier than your Contract_NetStartDate.
For syntax, see here -
http://www.w3schools.com/sql/func_datediff.asp
For syntax, see here -
http://www.w3schools.com/sql/func_datediff.asp
What do you mean by "month"? That it crossed a calendar month, or that it was a minimum number of days for each "month"?