Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 41,990 of 42,547    |
|    Chris Roberts to Herbert Kleebauer    |
|    Re: DOS Batch program countdown days unt    |
|    04 Feb 22 14:11:00    |
   
   From: thecjguy1@gmail.com   
      
   On Wednesday, February 2, 2022 at 4:08:53 PM UTC-5, Herbert Kleebauer wrote:   
   > On 02.02.2022 20:18, Chris Roberts wrote:   
   >   
   > > That's a cool script, I may use it.   
   > > But it says it "extract from the %date% variable" and then does NOT use   
   %date% at all and instead statically defines the date.   
   > It says, you should extract the variables %y% %m% %d%   
   > from the %date% variable. Because the code depends on   
   > the local date format, it is not done in my example   
   > but instead some fixed values are used to show the   
   > usage of the two subroutines.   
   > > I don't totally get :day2date It seems like a lot of variables for this   
   simple task.   
   > If it is a simple task, then do it yourself and   
   > show us your code. Maybe there really is a much   
   > simpler solution (I wanted a version without "IF"   
   > and "GOTO").   
      
      
   JJ, thanks for your input.   
      
   Herbert Kleebauer,   
   You are correct. "then do it yourself and show us your code"   
   I really didn't know how to get the output of "date"   
   and then... do math with it. (I am way behind you guys on this DOS stuff).   
   I have worked more with at bash and python, but now at a windows centric job   
   so trying to learn to do it all again with DOS.. :-(   
      
   Here is what I have so far:   
   not worried about formatting.   
   and   
   No, It's not correct. There is NOT 30 days/month and NOT 365 days/year.   
   The examples you guys have provided in this thread has really helped me.   
   feel free to pick and refine any or all of it.   
      
   ####   
   @ECHO off   
   setlocal EnableDelayedExpansion   
   set dd=%date:~10,4%-%date:~7,2%-%date:~4,2%   
   :: separate the present year into fields   
   for /f "tokens=1,2* delims=- " %%A in ('ECHO %dd%') do (   
    Set PresY=%%A   
    Set PresD=%%B   
    Set PresM=%%C   
   )   
   :: separate the ret year into fields   
   set ret=2029-06-8   
   for /f "tokens=1,2* delims=- " %%G in ('ECHO %ret%') do (   
    Set RetY=%%G   
    Set RetD=%%H   
    Set RetM=%%I   
   )   
   set /a diff_y=%RetY%-%PresY%   
   set /a diff_m=%RetM%-%PresM%   
   set /a diff_d=%RetD%-%PresD%   
   echo Present date is: %dd%   
   echo Retirement date is: %ret%   
   echo time to wait is:   
   ECHO Years %diff_y%   
   ECHO Months %diff_m%   
   ECHO Days %diff_d%   
   ::calculat days until retirement.   
   set /a Days=%diff_y%*365+%diff_m%*30+%diff_d%   
   echo Days until retirement is %Days%   
      
      
   ###(OUTPUT)###   
   $ retire   
   Present date is: 2022-04-02   
   Retirement date is: 2029-06-8   
   time to wait is:   
   Years 7   
   Months 6   
   Days 2   
   Days until retirement is 2737   
   ###   
      
   --- 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