Search code examples
datex++erpdynamics-365-operations

How to find previous weeks date?


The method should retrieve the date in the previous week that corresponds most closely to the specified date.

fromdate = prevMth(systemDateGet());

need to change the above code so that i could get the date of the previous week instead of previous month with respect to the present date.


Solution

  • No function is needed, just use date arithmetic.

    systemDateGet() - 7
    

    This will return the prior week date. This of cause implies you use a calendar with 7 day weeks.

    Some additional things you may find useful:

    • wkOfYr(...)
    • dayOfWk(...)
    • DateTimeUtil::[VariousFunctionsHere]