Post by Herbert KleebauerI 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.. :-(
Why not activate the "Windows Subsystem for Linux" and use bash?
https://docs.microsoft.com/en-us/windows/wsl/
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%
Just a note: numbers staring with "0" are octal numbers.
So if RetD is "08", it can't be used in a "set /a" command
because 08 isn't a legal octal number.
Thank you Herbert,
I see what you mean on the "numbers staring with "0" are octal" (That is why it wouldn't work with "08" in retirement date. See, I am learned something already... Thanks. )
Lets just hope we don't have any months beyond August. :-)
I have usually have both (via ConEmu) DOS and a "Ubuntu bash prompt" up on my PC.
I just want to know more about DOS batch.
Also, I like that I can easily open apps from DOS. (ie: DOS's "start EditPadLite8.exe %1" just works better than my ubuntu's alias bb='notepad++.exe' as the later won't just accept any path)
So if I wanted to fit retirement.bat or some other garbage into another batch program that also opened my schedule in an excel spreadsheet I could.
I cleaned it up a bit: (Below)
@ECHO off
:: setlocal EnableDelayedExpansion ::Doesn't seem to make any difference, why do people use this anyway?
:: Need to add logic to permit to or ommit leading 0's from the date. due to Octal
set retirement_date=6-8-2027
::set dd=%date:~10,4%-%date:~7,2%-%date:~4,2%
set dd=%date:~4,2%-%date:~7,2%-%date:~10,4%
:: separate the present year into fields
for /f "tokens=1,2* delims=- " %%A in ('ECHO %dd%') do (
Set PresM=%%A
Set PresD=%%B
Set PresY=%%C
)
:: separate the retirement_date.
for /f "tokens=1,2* delims=- " %%G in ('ECHO %retirement_date%') do (
Set RetM=%%G
Set RetD=%%H
Set RetY=%%I
)
set /a diff_y=%RetY%-%PresY%
set /a diff_m=%RetM%-%PresM%
set /a diff_d=%RetD%-%PresD%
::ECHO retirment month %RetM%
::ECHO Pres month %PresM%
::ECHO retirment DAY %RetD%
::ECHO Pres DAY %PresD%
::ECHO %RetD%
ECHO Present date is: %dd%
ECHO Retirement date is: %retirement_date%
ECHO:
ECHO %diff_y% Years
ECHO %diff_m% Months
ECHO %diff_d% Days
::calculate days until your retirement.
set /a Days=%diff_y%*365+%diff_m%*30+%diff_d%
ECHO TIME TO WAIT until retirement is %Days% Days.
###OUTPUT###
$ retire
Present date is: 02-07-2022
Retirement date is: 6-8-2027
5 Years
4 Months
1 Days
TIME TO WAIT until retirement is 1946 Days.
###