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,508 of 68,980   
   Herbert Kleebauer to asyadav5@gmail.com   
   Re: Batch Script Yesterday date file for   
   18 Mar 20 18:32:45   
   
   From: klee@unibwm.de   
      
   On 18.03.2020 05:42, asyadav5@gmail.com wrote:   
   > Dear All,   
   >   
   > i am new for batch script language.   
   > can anyone help me to get yesterday date,   
   > in below code from the date i am doing minus 1 to get yesterday date but its   
   coming wrong when 1st date of each months, its giving dd 00 how we can handle   
   this scenario   
   >   
   > i need the format always like yyyymmdd 20200301   
      
   @echo off   
   setlocal disabledelayedexpansion   
      
   :: extract the variables %y% %m% %d% from the %date% variable   
   :: (this depends on the local date format)   
   :: valid year range: 1901-2099   
      
   set /a y=2004   
   set /a m=3   
   set /a d=1   
      
   call :date2day   
   set /a w=%w%-1   
   call :day2date   
      
   echo %y% %m% %d%   
   goto :eof   
      
      
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :: convert the date in %y% %m% %d% to the number of days (%w%) ::   
   :: since 1901  (day 0 is 1. Jan. 1901)                         ::   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
      
   :date2day   
   set /a w=(%y%-1901)*365+(%y%-1901)/4+%d%-1+(!(%y% %% 4))*(!((%m%-3)^&16))   
   set /a w=(%w%+(%m%-1)*30+2*(!((%m%-7)^&16))-1+((65611044^>^>(2*%m%))^&3))   
   echo %y% %m% %d% %w%   
   goto :eof   
      
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :: convert the number of days in %w% to the date (%y% %m% %d%) ::   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
      
   :day2date   
   set /a x=%w%/1461   
   set /a w=%w%-%x%*1461   
   set /a z=%w%/365-((%w%/365)^>^>2)   
   set /a w=%w%-%z%*365   
   set /a y=1901+%x%*4+%z%   
   set /a v=%w%-!(%y% %% 4)   
   set /a m=!!(%w%/31)+!!(%v%/59)+!!(%v%/90)+!!(%v%/120)+!!(%v%/151)+!!(%v%/181)   
   set /a m=%m%+!!(%v%/212)+!!(%v%/243)+!!(%v%/273)+!!(%v%/304)+!!(%v%/334)+1   
   set /a d=%w%+1-(!(%y% %% 4))*(!((%m%-3)^&16))   
   set /a d=%d%-((%m%-1)*30+2*(!((%m%-7)^&16))-1+((65611044^>^>(2*%m%))^&3))   
   goto :eof   
      
   --- 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