0

I am new in Sharepoint 2013 and need a little help.

I am trying to get the difference between two dates and the result should be a year. Is there a way to do this in the String Builder?

Example:

1.5.1973 and 1.1.1980 = 7

4.2. 1985 and 1.1.1980 = 5

1

1 Answer 1

0

If all you want is simply a difference in the Years then you can use this:

DateTime lValue = 1.5.1973;
DateTime rValue = 1.1.1980;
StringBuilder str = new StringBuilder();
str.Append(rValue.Year - lValue.Year);

Note that this returns a relative difference, meaning that if rValue is greater than lValue, then the return value will be negative. If you want an absolute difference, you can use this:

DateTime lValue = 1.5.1973;
DateTime rValue = 1.1.1980;
StringBuilder str = new StringBuilder();
str.Append(Math.Abs(rValue.Year - lValue.Year));
2
  • 1
    He meant the stringbuilder in SharePoint Designer Commented May 10, 2016 at 12:15
  • Sorry but i didn't checked the tags for the question.
    – Hardik
    Commented May 10, 2016 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.