Find the cost price based on the date

Hi Friends,

I am using the below code to get the item cost price. It is working fine, but in my case the cost price will change based on the date. I believe the below code getting the current date cost price. How do I find the past date cost price. For example, before two days or weeks what is the cost price for the item.

Please help me to solve this issue.

static void Hari_FindItemCostPrice(Args _args)
InventDim inventDim, inventDimCriteria;
ItemId itemId;
InventDimParm inventDimParm;
date onHandDate;
InventSumDateDim inventSumDateDim;
InventOnHand inventOnHand;

itemId = ‘a004’;
inventDimCriteria.inventLocationId = ‘11’;

inventOnHand = InventOnHand::newItemDim(itemId, inventDimCriteria, inventDimParm);
info(strfmt(’%1’, inventOnHand.costPricePcs()));