Search code examples
winformscrystal-reports

Crystal Report last three years in text objects using formula


I want to make something like that using formula

the years are Changing according to this year

The years are changing according to this year

I am a completely Beginner

Thanks for your help !


Solution

  • You can piece it together with the following bits. See the CR help text for all the functions below if you don't understand how they work or want more details.

    1. The DateAdd() function will allow you to add or subtract certain units of time to/from a DateTime. For example, if you want to get the date three years ago, you can use DateAdd('yyyy',-3,CurrentDate)
    2. Printing a date can be done via the ToText() function. To only print the year portion of the DateTime field, you can use ToText(CurrentDate,'yyyy') which will give you '2014'
    3. In CR, the newline character is chr(13). Concatenate that onto a string to print a newline wherever you'd like.

    EDIT: Since you already implemented it in C#, here's one possible CR solution:

    " : " + totext(dateadd('yyyy',-3,currentdate),'yyyy') + chr(13) +
    " : " + totext(dateadd('yyyy',-2,currentdate),'yyyy') + chr(13) +
    " : " + totext(dateadd('yyyy',-1,currentdate),'yyyy')