StrToDate('26-12-2015'); does not work ...?

edited January 2016 in FastReport VCL 5
Hi,

im working on a Delphi based report. Later the Programm will Hand over a Var called "DatumMontag" with a Notation like this 26-12-2015.

For testing purposes this var has been set in the Code as '''26-12-2015''' (in the way it will be hand over later aswell)..., however the StrToDate() function does not work properly and i got an error Message with " ... 'DatumMontag' is no valid date "

I think im doing it wrong somehow...
procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
begin

StrToDate('DatumMontag');    
  
end;

what should i do to correct it?


Well thats the easy part so far i think... later i will need to add 6 Days to this Date too. in my first attempts i successed adding days to this Date BUT when i add 6 Days to the 26-12-2015 i get 32-12-2015 instead of 01-01-2016 ...

can someone pls explain how to do this like intended..

Ty!

Comments

  • edited 3:38PM
    If you want to use the variable DatumMontag, you need to remove the quote. Those quotes means that the text inside is not a variable, but the string that you are trying to convert as a date.

    Do as follow : StrToDate(DatumMontag)
  • edited 3:38PM
    Hi, thx for replay.

    Well i have removed those quotes and i now get the "undeclared indentifier: 'DatumMontag'" error...


    i've tried a few things and im always landing on that or some similar errors...


    Thats how it currently looks like:
    procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
    
    Set ('DatumMontag','''26-12-2015''');    
      
    StrToDate(DatumMontag);
      
    end;
    
  • edited January 2016
    I thought you were using DatumMontag as a script variable, but you are using it as a report variable. In your case, you need to use the method Get :
    procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
    
    Set ('DatumMontag','''26-12-2015''');    
      
    ShowMessage('My date + 6 days : ' + DateToStr(StrToDate(Get('DatumMontag'))+6));
      
    end;
    

    To do it as a script variable (the value of this kind of variable are local to the report, they can't be set externally), it would be as following :
    procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
    var
      DatumMontag: String;
    begin
      DatumMontag := '26-12-2015';  
      ShowMessage('My date + 6 days : ' + DateToStr(StrToDate(DatumMontag)+6)); 
    end;
    
  • edited 3:38PM
    Thx again for ur reply.

    i used ur first code snipped and got an "DatumMontag is no valid Date"-error...


    well. just to make sure that u know what the final result should look like.. (Damn, cant belive its soo hard to get this simple thing done... [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> ... ) on the Top of the Report Page there will be a certain Date. This Date could be any Monday of a Month and will be Hand over by a SAP-like Program in a notation like this "26-12-2015". The Var has been set via 'Report > Variables' in the top Menu-Band of FR and filled via the Set command with the 26-12-2015 (for testing purposes; it will be out-commented later) in the code. Somehow FR ist not able to recognize this Simple Var written in a Memofield [DatumMontag] ... as an actual Date, so that Format settings are ignored so far,... it could have been sooo easy if that would work... Anyway. Since that does not work im trying to use the StrToDate function which is not able to fix this either it seems..! I really like to skip this Date-Stuff but unfortunately i need this date +6 Days in the Report itself again. Ty[/img]
  • edited 3:38PM
    If you get a date error using the first code snippet, it is most likely because your string ( '26-12-2015' ) is not valid. Did you try to use a date that is in the format of the computer? I know my computer date format is "yyyy-mm-dd" and when I use the first code snippet with the date '2015-12-26' it works without any problem.
  • edited 3:38PM
    my Date-Format is dd.mm.yyyy and it will be the same on all client PCs which will use this report in the end. So i think it would not be a good choiche if i switch to another Date-Time Format on my PC.

    So this err might be forced by PC settings? :S
  • edited 3:38PM
    Hias wrote: »
    my Date-Format is dd.mm.yyyy and it will be the same on all client PCs which will use this report in the end. So i think it would not be a good choiche if i switch to another Date-Time Format on my PC.

    So this err might be forced by PC settings? :S

    I'm not saying to change anything for the long term. Just try it to see if you can make it work.. then we can go and find a solution once we find why the same code snippet work for me and not for you.
  • edited 3:38PM
    I am still baffled how such kind of problems have not been solved yet, 5 years creating reports with fastreports and it still feels quite broken using dates and report variables.
  • edited 3:38PM
    I am still baffled how such kind of problems have not been solved yet, 5 years creating reports with fastreports and it still feels quite broken using dates and report variables.

    Creating simple reports with FR is really Fast but when creating some moderate complex or complex reports, it is very very hard. Often our team members stuck resolving simple calculations and tasks. Struggling with display formats, calculations in scripts, etc. But all these still run Fast. Often it takes quite a lot time for simple tasks even without struggling. Even selecting and changing font, style, display format and some common properties of 7-8 objects will irritate you.

  • gpigpi
    edited 3:38PM
    wrote:
    Often our team members stuck resolving simple calculations and tasks. Struggling with display formats, calculations in scripts, etc.
    Did you try to contact FR support (support@fast-report.com)?

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.