DateFormula................

Angelo
Angelo Member Posts: 180
Hello,Master

I wanna ask small question :
I have variable "periodLength " type dateformula.

then, I want to use calcdate for calculate date :

periodStartdate := calcdate(periodlength,WORKDATE);

if I fill periodlength ==> 1M

I want to 'calcdate' 1 month ago by coding :

periodStartdate := calcdate(-periodlength,WORKDATE); or
periodStartdate := calcdate('-periodlength',WORKDATE);
it will show error message,How I can use dateformula by using prefix 'minus' ?

please help me...... ](*,)

Comments

  • Frank_Raemakers
    Frank_Raemakers Member Posts: 25
    EVALUATE(PeriodLength,'-1M');
    PeriodStartDate := CALCDATE(PeriodLength,TODAY);


    Greats

    Frank
  • Angelo
    Angelo Member Posts: 180
    Sorry,Frank,maybe there is misunderstanding..

    I make a control textbox with souce expresion "periodlength" type dateformula,so user can fill it : 1Y,1M,2W,so on(periodlength is dynamic). afterwards,I want to use the variable(periodlength) for calculate date by using CALCDATE. if user fill it : "1M", when I calculate it, I want to calculate as "-1M" for assigning to periodstartdate like this :

    periodStartdate := calcdate(-periodlength,WORKDATE); or
    periodStartdate := calcdate('-periodlength',WORKDATE);

    but error.....

    What should I have to do for solving my problem above?
    anyone can give me advice? [-o<

    regards,
    Angelo....
  • Wolfikas
    Wolfikas Member Posts: 13
    calcdate(STRSUBSTNO('-%1', periodlength),WORKDATE)

    but it will work incorrect if you enter dataformula like 1Y+2M
    Virginijus
  • randrews
    randrews Member Posts: 135
    DF - DateFormula (input from form)
    D - Date (input from form)
    RD - Date (result date)

    If DF would such as '1D' or '1M' then
    RD := CALCDATE('-'+FORMAT(DF),D);

    THE BEST WAY:
    But if DF is for example '1M+1D-1W' then
    RD := CALCDATE(DF,D);
    RD := D - (RD-D);

    It works. I cheked.
  • randrews
    randrews Member Posts: 135
    THE BEST WAY:
    But if DF is for example '1M+1D-1W' then
    RD := CALCDATE(DF,D);
    RD := D - (RD-D);

    My error. This counts days. Error can apears when month with diferent days (28.29.30.31)

    So may be it wil work:

    RD := CALCDATE('-('+FORMAT(DF)+')',D);