home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,771 of 68,980   
   Zaidy036 to Tom Del Rosso   
   Re: Get date of recent weekday   
   02 Sep 21 11:04:50   
   
   From: Zaidy036@air.isp.spam   
      
   On 9/2/2021 3:34 AM, Tom Del Rosso wrote:   
   > This might not be useful to anyone else, but it's worth mentioning. I   
   > numbered the lines this time because a lot of them will wrap.   
   >   
   > I have an event that happens every Friday, and I have a batch to make a   
   > folder with a date-name and put weekly files in the folder.   
   >   
   > If I run the batch on another day, I want it to refer to the folder   
   > whose name is the date of the last Friday, so this routine provides the   
   > date.   
   >   
   > It's easy to change to Monday by shifting the numbers on line 12.   
   >   
   >   
   > [01] :get_last_friday_date   
   > [02] rem  returns variable _last_friday_date in the form YYYY-MM-DD   
   > [03] rem  if run on Friday, returns today's date [if Fri=0 is changed to   
   > Fri=7 then it would return last week's]   
   > [04] rem  month lengths from Dec to Nov days-28   
   > [05] set "_MonthLengths=x330323233232"   
   > [06] for /f "tokens=1-4 delims=/ " %%a in ("%date%") do (   
   > [07]  set "_weekday=%%a"   
   > [08]  set /a _month=1%%b - 100   
   > [09]  set /a _day=1%%c - 100   
   > [10]  set /a _year=%%d   
   > [11] )   
   > [12] set /a Sun=2, Mon=3, Tue=4, Wed=5, Thu=6, Fri=0, Sat=1   
   > [13] call set /a _weekdaynumber=%%%_weekday%%%   
   > [14] set /a _last_friday_day = _day - _weekdaynumber   
   > [15] set /a _last_friday_month = _month   
   > [16] set /a _last_friday_year = _year   
   > [17] if %_last_friday_day% LSS 1 (   
   > [18]  call set /a "_last_friday_day += 28 +   
   > %%_MonthLengths:~%_month%,1%% + !(_year %%%% 4) * !(_month-3)"   
   > [19]  set /a "_last_friday_month = (_month + 10) %% 12 + 1"   
   > [20] )   
   > [21] if %_last_friday_month% EQU 12 if not %_month% EQU 12 set /a   
   > _last_friday_year -= 1   
   > [22] set "_last_friday_month=0%_last_friday_month%"   
   > [23] set "_last_friday_month=%_last_friday_month:~-2,2%"   
   > [24] set "_last_friday_day=0%_last_friday_day%"   
   > [25] set "_last_friday_day=%_last_friday_day:~-2,2%"   
   > [26] set   
   > "_last_friday_date=%_last_friday_year%-%_last_friday_month%-%_   
   ast_friday_day%"   
   > [27] goto :eof   
   >   
   >   
   >   
   If you do a lot of date calculations I suggest using Julian dates to   
   make logic simpler.   
      
   Look at    
      
   Make two batches <1>DateToJ and <2>DateToC. Run <1>, apply logic, run   
   <2>, generate folder name.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca