How to find previous weeks date?

Viewed 220

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.

2 Answers

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]

In D365FinOps you can also use:

HcmDateTimeUtil::calculateDateWithOffset(PeriodUnit::Day,7,false)
Related