How to calculate - Same day next year

ajhvdbajhvdb Member Posts: 672
My customer has a special calendar table. He wants a function to copy all records to the next year (but keep the same day).

monday: 1 september 2008 --> monday: 31 august 2009
etc.
friday: 5 september 2008 --> friday: 4 september 2009
etc.


Can i use calcdate for this?

Answers

  • hs_mannhs_mann Member Posts: 17
    Hi

    Try using CALCDATE('+52W', YourDate)

    Harjot
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Take a look at virtual table Date. Could be something like that...
    DateRec.SETRANGE("Period Type",DateRec."Period Type"::Day);
    DateRec.SETRANGE("Period Start",CALCDATE('<CW + 1Y - 1W>',YourDate),CALCDATE('<CW + 1Y - 1D>'),YourDate);
    DateRec.SETRANGE("Period No.",GetPeriodNoOfYourDate);
    
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • ajhvdbajhvdb Member Posts: 672
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    ajhvdb wrote:
    This one? <CW + 1Y - 1W>
    Current Week + 1 Year - 1 Week
    CW returns the last day of the current week.
    I didn't test it. Maybe it's
    DateRec.SETRANGE("Period Start",CALCDATE('<CW + 1Y - 1W + 1D>',YourDate),CALCDATE('<CW + 1Y>'),YourDate);
    
    You should try it.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • DenSterDenSter Member Posts: 8,305
    +52W makes most sense to me (haven't actually tried either one).
  • SavatageSavatage Member Posts: 7,142
    Terms = 1year = +52w
    I tested it - If i enter an order today 10/02/2008 the due date is 10/01/2009

    Terms = 1year = CW+1Y-1W
    I tested it - If i enter an order today 10/02/2008 the due date is 09/28/2009

    So it looks like your looking for +52W+1D
  • DenSterDenSter Member Posts: 8,305
    Today (October 2 2008) is a Thursday. October 1, 2009 is also a Thursday. If I read the original question right, this is exactly what he's looking for.
  • SavatageSavatage Member Posts: 7,142
    Hmm I guess - I was thinking he wanted 10/02/2008 & 10/02/2009.

    Either way he has a choice.
    i guess then +1y-1d give you the same answer

    Here's a oldie
    Navision Data Calculator
    http://www.mibuso.com/dlinfo.asp?FileID=514
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    I guess <+1Y - 1D> and <+52W -1D> will not work because of leap years.
    That's why I refered to the Date table.
    I think it should be something like that...
    Date.RESET;
    Date.SETRANGE("Period Type",Date."Period Type"::Day);
    Date.SETRANGE("Period Start",YourDate);
    Date.FINDFIRST;
    
    Date2.RESET;
    Date2.SETRANGE("Period Type",Date2."Period Type"::Day);
    Date2.SETRANGE("Period Start",CALCDATE('<CW + 1Y - 1W + 1D>',YourDate),CALCDATE('<CW + 1Y>',YourDate));
    Date2.SETRANGE("Period No.",Date."Period No.);
    Date2.FINDFIRST;
    
    Then Date2."Period Start" is your new Date. Next year, same day of week.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • SavatageSavatage Member Posts: 7,142
    I tested +1y-1d worked for both regular & leap years unless we're talking about the DAY OF THE WEEK??
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Savatage wrote:
    I tested +1y-1d worked for both regular & leap years unless we're talking about the DAY OF THE WEEK??
    Yeah, I think he wants to get the same day of the week.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • DenSterDenSter Member Posts: 8,305
    <+52W> is the answer in my opinion, that is always the same weekday, and 52 weeks is as close as you can get to one year. <+1Y> gives you the same date one year from the start date, which is always a different weekday. <-1D> will always give you problems in case of leapyears. Using the date table should always work, but is much more complex, for exactly the same result as <+52W>.

    I guess it should be defined, something like "the date that has the same weekday, that is as close to 1 calendar year from the start date as possible".
  • ajhvdbajhvdb Member Posts: 672
    Thx, never thought of <+52W>

    They are setting up a grow plan for plants. This needs to start the next year again on monday, ...
  • DenSterDenSter Member Posts: 8,305
    Credit goes to:
    hs_mann wrote:
    Try using CALCDATE('+52W', YourDate)
    :mrgreen:
Sign In or Register to comment.