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

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));
  • 1
    He meant the stringbuilder in SharePoint Designer – Danny '365CSI' Engelman May 10 '16 at 12:15
  • Sorry but i didn't checked the tags for the question. – Hardik May 10 '16 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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