Page 1 of 1

Find previous business day

Posted: Mon Sep 03, 2018 10:04 am
by satheesh_color
Hi All,

Do you have any idea on how to find the previous business/working day from the given date. is there any inbuilt function available or do we need to write any routine...


Kindly let me know your thoughts on the same.


Thanks.

Posted: Mon Sep 03, 2018 12:53 pm
by ray.wurlod
This is a universal problem best solved through use of a calendar file/table.

"Business day" could be any day of the week. For example, today is Monday in the USA, but it's a public holiday and therefore not a business day (officially) despite the fact that most stores are open and having sales.

Posted: Tue Sep 04, 2018 9:58 am
by FranklinE
If you don't have a calendar function, like in Control-M, a simple design suggestion:

Identify all jobs that depend on having an accurate previous business day date.

Have the last job update a previous business date file with the current date. This implies that all of those jobs must complete before the update.

The next business day jobs use the file for the previous business day date.

We use this design to avoid problems such as not all jobs conform to the holiday schedule. The challenge is grouping jobs that depend on the same date setting, and give each group its own file.

Re: Find previous business day

Posted: Thu Sep 06, 2018 2:53 pm
by Sumith
If you have list of holidays loaded into a file or a table, do a lookup, you can use the below query in case of DB2 and write it to a file:

SELECT CASE WHEN DAYNAME(CASE('#PprmCycledate#' AS DATE)) = 'Saturday'
THEN CAST('#PprmCycledate#' AS DATE) - 1 DAY
END A CycleDate FROM SYSIBM.SYSDUMMY1

Posted: Thu Sep 06, 2018 5:36 pm
by ray.wurlod
Not really a complete/generic solution, though, is it? :cry:

Posted: Thu Sep 06, 2018 11:00 pm
by satheesh_color
Hi All,

Appreciate for your information.

Currently we are building CalendarHoliday table for different regions(US/UK & ANZ)...which includes public holidays and weekends(Sat&Sun). Once this gets done we will do a lookup against the table to get the required date.

Basically we are looking to calculate the delivery date from the given date with the priority the customer would choose.


Thanks.

Posted: Fri Sep 07, 2018 5:46 am
by chulett
So, resolved it would seem - yes?

Posted: Sat Sep 08, 2018 7:04 pm
by ray.wurlod

Code: Select all

SELECT A.THE_DATE FROM CALENDAR A WHERE A.THE_DATE = (SELECT MAX(B.THE_DATE) FROM CALENDAR B WHERE B.THEDATE <= A.THE_DATE AND B.BUSINESS_DAY = 'Y');