business day date math ideas

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

business day date math ideas

#1 Post by avery_larry » 23 Jul 2013 19:47

I'm just looking for ideas on date math but skipping weekends (and holidays maybe).

I've got a scanning (paper to pdf) process that's partly done by people, and partly done by computers. I'm going to track the progress of individual batches via a simple log file concept.

Well anyway -- I have a monitoring script that I just want to use simply to alert people if a batch sits too long at any given stage. For instance, it shouldn't take more than 2 days to get around to checking that a batch finished processing properly. The trick is that the people portions need to check for 2 business days.

Anyone got any better ideas than the simple (but annoying) 5 separate cases based on day of week?

Aacini
Expert
Posts: 1910
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: business day date math ideas

#2 Post by Aacini » 23 Jul 2013 21:52

Although I don't completely understand your concern, I think the Batch file below may help you. This Batch file get the Day of the Week of current date as an integer value from 0 (Sunday) to 6 (Saturday). This value may help you to know if a date (or a past/future date) falls on weekends or on business days.

Code: Select all

@echo off
setlocal
call :DateToJDN "%date%" jdn=
set /A dow=(jdn+1)%%7
echo Today's Day of Week is: %dow%
goto :EOF


:DateToJDN locale_date jdn=
setlocal EnableDelayedExpansion
set "date=%~1"
set dateFormat[0]=mm=10%%a%%100, dd=10%%b%%100, yyyy=100%%c%%10000
set dateFormat[1]=dd=10%%a%%100, mm=10%%b%%100, yyyy=100%%c%%10000
set dateFormat[2]=yyyy=100%%a%%10000, mm=10%%b%%100, dd=10%%c%%100
for /F "tokens=1,2*" %%a in ('reg query "HKCU\Control Panel\International" ^| findstr /I "\<[is]Date\>"') do set "%%a=%%c"
set dateValues=!dateFormat[%iDate%]!
for /F "tokens=1-3 delims=%sDate%" %%a in ("%date:* =%") do set /A %dateValues%
if %yyyy% lss 100 (
   if %yyyy% lss 70 (set /A yyyy+=2000) else (set /A yyyy+=1900)
)
set /A a=(mm-14)/12, jdn=(1461*(yyyy+4800+a))/4+(367*(mm-2-12*a))/12-(3*((yyyy+4900+a)/100))/4+dd-32075
endlocal & set %2=%jdn%
exit /B

If you have further questions about how to modify this method, don't hesitate to post new questions.

Antonio

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: business day date math ideas

#3 Post by penpen » 24 Jul 2013 06:27

avery_larry wrote:Anyone got any better ideas than the simple (but annoying) 5 separate cases based on day of week?

You may map the dates (of DateSpace) to their index of business day in the current year (of BusinessDateSpace); non busisess dates are mapped to the last business day just prior to them.
Then add 2 and map the result back to DateSpace.

penpen

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: business day date math ideas

#4 Post by avery_larry » 29 Jul 2013 12:06

Well, it was worth a shot. I'll just code it the long way basically using what Aacini posted.

Post Reply