What is the peak number of transactions posted per hour?

Hello Everyone,

I have got a strange requirement and I dont know where to start.

Management wants to know the peak number of item arrival journal posted per hour.

Similarly, the peak number of purchase and sales order created in system per hour. The idea behind this exercise is to figure out the busiest hour in a day.

I could manage to extract the number of transactions per day and then report the busiest day but don’t know how to find busiest hour.

This is my code returning per day information:

InventJournalTable fromTable, toTable, TransTable;
FromDate fromDate;
ToDate toDate;
FromDateTime fromDateTime;
ToDateTime toDateTime;
int64 lastRecords;
Date _Currentdate;
utcDateTime _UtcCurrentPeriod;
utcDateTime _UtcEndPeriod;

select firstOnly toTable order by PostedDateTime Desc where toTable.PostedDateTime;
toDate = DateTimeUtil::date(toTable.PostedDateTime);

select firstOnly fromTable order by PostedDateTime Asc where fromTable.PostedDateTime;
fromDate = DateTimeUtil::date(fromTable.PostedDateTime);

while (fromDate < toDate+1)
{
_UtcCurrentPeriod = DateTimeUtil::newDateTime(fromDate,0);
_UtcEndPeriod = DateTimeUtil::newDateTime(fromDate,86400);

select count(RecId) from TransTable where TransTable.PostedDateTime >= _UtcCurrentPeriod && TransTable.PostedDateTime <= _UtcEndPeriod;
if (TransTable.RecId > lastRecords)
{
info(strFmt(“From Date %1 to Date %2 Last Records %3 number of Records %4”, _UtcCurrentPeriod, _UtcEndPeriod, lastRecords, TransTable.RecId));
lastRecords = TransTable.RecId;
}

fromDate+=1;
}

Can someone please put me in to right direction?

I think the easiest way is using direct T-SQL (in SQL Server Management Studio), even if you’re not familiar with it. T-SQL supports much more complex queries, including grouping data by the result of DATEPART() function.

Hello Ayesha,

I have completed the query for you. Let me know if this works.

static void JZS_TransactionPerHour(Args _args)

{

InventJournalTable fromTable, toTable, TransTable;

FromDate fromDate;

ToDate toDate;

utcDateTime fromDateTime;

utcDateTime toDateTime;

Date _Currentdate;

utcDateTime _UtcCurrentPeriod;

utcDateTime _UtcEndPeriod;

int hrno = 1;

select firstOnly toTable order by PostedDateTime Desc where toTable.PostedDateTime;

toDate = DateTimeUtil::date(toTable.PostedDateTime);

select firstOnly fromTable order by PostedDateTime Asc where fromTable.PostedDateTime;

fromDate = DateTimeUtil::date(fromTable.PostedDateTime);

while (fromDate < toDate+1)

{

_UtcCurrentPeriod = DateTimeUtil::newDateTime(fromDate,0);

_UtcEndPeriod = DateTimeUtil::newDateTime(fromDate,86400);

fromDateTime = _UtcCurrentPeriod;

toDateTime = DateTimeUtil::newDateTime(fromDate,3600);

while (fromDateTime < _UtcEndPeriod)

{

hrno++;

select count(RecId) from TransTable where TransTable.PostedDateTime >= fromDateTime && TransTable.PostedDateTime <= toDateTime;

info(strFmt(“From Date %1 to Date %2 number of Records %3”, fromDateTime, toDateTime, TransTable.RecId));

fromDateTime = DateTimeUtil::newDateTime(fromDate,3600*hrno);

toDateTime = DateTimeUtil::newDateTime(fromDate,3600*(hrno+1));

}

hrno = 1;

fromDate+=1;

}

}

Thanks Jahan ! It really helped me

Thanks Martin for your help, Unfortunately, I dont have access to SMS.