Add Days or Months to a date?

edited 11:46AM in FastReport 4.0
Hey there - first post here...love FR4!

First off - am using FR v4.10.1

OK...I'm trying to simply add either months or days to database date and I've tried all kinds of ways, but just can't figure it out. Some examples I tried:

[frxDBRep."repDate"]+180
[frxDBRep."repDate"]+(180)
[[frxDBRep."repDate"]+(180)]
frxDBRep."repDate"]+[180

....all to no avail. [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> So doing a search here in the Forum...came across a post in the .NET forum and come to find out there is a function "AddMonths" in the .NET version (and other similar ones) that easily can do this:[/img] http://www.fast-report.com/en/forum/index....mp;hl=addmonths

So...is there a way to do this in FR4? So according to that thread...if I were to do this in the .NET version and add 6 months, should look something like this:

AddMonths([frxDBRep."repDate"],6)

On the same note - will FR4 ever get those extended functions that .NET version of FR has?

Thanks!
Fred

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 11:46AM
    if this text in a memo
    [frxDBRep."repDate"]+180
    change to
    [(<frxDBRep."repDate"> + 180)]

    fr4 has all kinds of functions and there is also an additional function lib on Stalkers site
    and you can also write and add your own function libs.
  • edited 11:46AM
    awesome....worked perfect, gordk!

    thanks alot for the quick reply as well....I saw it when you posted it and then something came up that tied me up for the rest of the day, but really appreciate you getting back to me so damn quick. [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> Cheers, Fred[/img]
  • edited 11:46AM
    OK...unfortunately this is not working how I originally thought it would as it's not exactly 6 months - to the date.

    For example this is how it is returning +180 days.

    Report Date = July 9, 2006

    +180 days later returns = January 5, 2007

    6 months should really be January 9, 2007.

    Is there any way I can fix this in Fast Report? If not....can I do the calculation in Delphi code (before previewing the report) so to pass the variable (6 month date) to the report for the 6 month date?

    Thanks for any help!
  • edited 11:46AM
    To better understand what I need....Delphi has a function called "IncMonth" which can increase the date by so many months.

    http://www.delphibasics.co.uk/RTL.asp?Name=IncMonth
  • gordkgordk St.Catherines On. Canada.
    edited 11:46AM
    All the additional functions are available from Stalker at
    http://stalker4.dp.ua/en/
  • edited 11:46AM
    thanks gordk.

    OK, I downloaded the "frxAddFunctionLibrary 4.51" library and tried to install the "frxAddFunction14.dpk" package which seems to be the latest one since I'm using Delphi XE, but I'm getting an error message when I try to Install it (Builds fine though):

    Error
    Cannot load package 'fs14.' It contains unit 'fs_tree', which is also contained in package 'fs15'.
    OK

    I also tried copying some of the *.pas files starting with the "date" function one until my app could compile, but I still can't get the function to work as it says it does not recognize the function "IncMonth" or "frIncMonth".

    So...I'm at lost here already gordk, so appreciate if you have any idea on how I can get this to work in Delphi XE. [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> BTW - I've got FastReport v4.10.1 installed (in Delphi XE) Thank you!![/img]
  • edited 11:46AM
    Have a look at simple example below. You can make it on your own.
    All what you must do is to take care of last day in different months (28,29,30,31)
    function IncMonth( FDate :TDateTime) :TDateTime;
    var Year,Month,Day :int;                                                                    
    begin
      DecodeDate(FDate, Year, Month, Day);
      if Month < 12
        then Result := EncodeDate( Year,   Month+1, Day)
        else Result := EncodeDate( Year+1, 1,       Day)                      
    end;          
      
    begin                                                                 
       ShowMessage( DateToStr( IncMonth(<DATE>)));                                                    
    end.
    

    Mick
  • edited 11:46AM
    Upssss - I attached an example of FR script, but I'm sure you can easilly change this idea into a Delphi code [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Mick[/img]
  • gordkgordk St.Catherines On. Canada.
    edited 11:46AM
    Woodie I did not realize you were working with xe.
    you should be able to rename all the pgks of the function lib to 15 and any refrences to in pas files to from 14 to 15
    then recompile and install.
  • edited May 2011
    Guys - thanks alot for your help....I managed to finally get it working after pulling a few hairs out. LOL

    "frxAddFunctionLibrary 4.51" package actually DOES install fine in Delphi XE, you just need to remove the reference to "frx14.dcp" in the Package and once you hit Build, it comes up asking to add a 4 or 5 other components in which before I must have clicked "Cancel", but clicking "OK"....and Building/Compiling it and Installing it....it worked just fine.

    I got it working as well by just throwing all the *.pas files to my main app directory and adding them all to the top uses clause. The nice thing about installing the Package is that it adds those functions to the Expression Editor, which is cool.

    gordk- is there any chance to make those functions/components on Stalkers' page - a permanent part of FastReport? I don't see why they can't just be incorporated into FR especially since it looks like those components/functions are mature and have been around since v2. Obviously I don't know the relation between FR and Stalker....but whatever, thank you so much for the link.....it got me back in business here!! LOL

    So to help others, here is the final code I used in the Script page of this particular report I'm working on.

    Thanks again guys!
    Cheers
    procedure Memo15OnAfterData(Sender: TfrxComponent);
    var          
      myDate: TDateTime;
      myYear, myMonth, myDay: Word;
      NextDate: TDateTime;
      strNextDate: String;                                             
    begin
      myDate := <frxDBRep."repDate">;
      NextDate := IncMonth(myDate,6);
      strNextDate := FormatDateTime('mmmm dd, yyyy', NextDate);                                    
      Memo3.Text := 'Next Examination Date: ' + strNextDate;  
    end;
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.