Code: Select all
@ECHO OFF &Setlocal DisableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%== Setting LF ==%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET LF=^
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%== Defining Macros ==%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
SET NL=^^^%LF%%LF%^%LF%%LF%
SET macro_Call=FOR /f "tokens=1-26" %%a IN
SET macro.Jdate=DO (%\n%
SetLocal EnableDelayedExpansion%\n%
SET DateStr=%%~a^&IF "%%~a"=="" set "DateStr=%DATE%"%\n%
FOR /F "skip=1 tokens=2-4 delims=(-)" %%A in ('"echo.|date"') do (%\n%
FOR /F "tokens=1-3 delims=/.- " %%G in ("!DateStr:* =!") do (%\n%
SET %%A=%%G^&SET %%B=%%H^&SET %%C=%%I))%\n%
SET /a "yy=10000!yy! %%10000,mm=100!mm! %% 100,dd=100!dd! %% 100"%\n%
IF !yy! LSS 100 SET /a yy+=2000%\n%
SET /a JD=!dd!-32075+1461*(!yy!+4800+(!mm!-14^^)/12^^)/4+367*(!mm!-2-(!mm!-14^^)/12*12^^)/12-3*((yy+4900+(!mm!-14^^)/12^^)/100^^)/4%\n%
FOR %%v IN (!JD!) DO ENDLOCAL^&IF "%%~b" neq "" (set "%%~b=%%v") else echo %%v%\n%
)
SET macro.Jdate2Date=DO (%\n%
SetLocal EnableDelayedExpansion%\n%
SET /a L=%%~a+68569,N=4*!L!/146097,L=!L!-(146097*!N!+3^^)/4,I=4000*(!L!+1^^)/1461001%\n%
SET /a L=!L!-1461*!I!/4+31,J=80*!L!/2447,K=!L!-2447*!J!/80,L=!J!/11%\n%
SET /a J=!J!+2-12*!L!,I=100*(!N!-49^^)+!I!+!L!%\n%
SET /a YYYY=!I!,MM=100+!J!,DD=100+!K!%\n%
SET MM=!MM:~-2!%\n%
SET DD=!DD:~-2!%\n%
SET "DOUT=!MM!/!DD!/!YYYY!"%\n%
FOR %%v IN (!DOUT!) DO ENDLOCAL^&IF "%%~b" neq "" (set "%%~b=%%v") else echo %%v%\n%
)
Setlocal EnableDelayedExpansion
:: Calling Macros
%macro_CALL% ("%TODAY% NEWJD") %macro.Jdate%
ECHO NEWJD= %NEWJD%
%macro_CALL% ("%NEWJD% NEWDATE") %macro.Jdate2Date%
ECHO %NEWDATE%
pause
Endlocal &exit /b
EDIT:
Added relative parts of the script for trouble-shooting purposes, Out of context the macros wouldn't mean much to most.