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,791 of 68,980    |
|    mokomoji to All    |
|    Re: Get date of recent weekday    |
|    07 Sep 21 11:00:43    |
   
   From: mokomoji@naver.com   
      
   2021년 9월 2일 목요일 오후 4시 40분 16초 UTC+9에 Tom Del   
   Rosso님이 작성한 내용:   
   > 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   
      
   @echo off   
   setlocal   
   cd /d %~dp0   
      
   set "z_day1=mon" ::1   
   set "z_day2=tue" ::2   
   set "z_day3=wed" ::3   
   set "z_day4=thu" ::4   
   set "z_day5=fri" ::0   
   set "z_day6=sat" ::1   
   set "z_day7=sun" ::2   
      
   for /f "tokens=1* delims==" %%f in (   
   'wmic path win32_localtime get dayofweek /value'   
   ) do (   
   if "%%~g" neq "" (   
   call set "z_toweek=%%%%%!%z_day%%~g%!%%%%%"   
   call set z_dayx=%%g   
   call set /a "z_value1=(%%z_dayx%% %%%%5)"   
   call set /a "z_value2=!(%%z_dayx%%/5)*2"   
   call set /a "z_value3=%%z_value1%%+%%z_value2%%   
   ))   
   echo Monthly do not with   
   echo Leap years do not with   
   call echo today "%z_toweek%" "%date:~-2%" day -"%z_value3%" day = last friday   
      
   pause   
   endlocal   
      
   --- 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