Say you have a date, 10/30/2015. The month, day, and year are stored as variables you can access. For example:
Code: Select all
SET MM=10
SET DD=30
SET YYYY=2015
Code: Select all
ECHO MM/DD/YYYY
Ideas?
Moderator: DosItHelp
Code: Select all
SET MM=10
SET DD=30
SET YYYY=2015
Code: Select all
ECHO MM/DD/YYYY
Code: Select all
C:\BatchFiles\JGetTimeStamp>getTimeStamp -d '10-30-2015' -od -60 -f {yyyy}{mm}{dd}
20150831
But this is hybrid. I want to do it in pure batch.Squashman wrote:I would just use Dave's GetTimeStamp.batCode: Select all
C:\BatchFiles\JGetTimeStamp>getTimeStamp -d '10-30-2015' -od -60 -f {yyyy}{mm}{dd}
20150831
Code: Select all
@echo off
setlocal EnableDelayedExpansion
:: Define YYYYMMDD date to Julian Day Number conversion function and viceversa
set "DateToJDN(YMD)=( a=(YMD), y=a/10000, a%%=10000, m=a/100, d=a%%100, a=(m-14)/12, (1461*(y+4800+a))/4+(367*(m-2-12*a))/12-(3*((y+4900+a)/100))/4+d-32075 )"
set "JDNtoDate(JDN)=( a=(JDN), l=a+68569,n=(4*l)/146097,l=l-(146097*n+3)/4,i=(4000*(l+1))/1461001,l=l-(1461*i)/4+31,j=(80*l)/2447,d=l-(2447*j)/80,l=j/11,m=j+2-(12*l),y=100*(n-49)+i+l,y*10000+m*100+d )"
SET MM=10
SET DD=30
SET YYYY=2015
SET DAYS=60
rem Convert the date to Julian Day Number
set /A "number=%DateToJDN(YMD):YMD=!YYYY!!MM!!DD!% - DAYS"
rem Increment the number and convert it back to date
for /L %%i in (1,1,%DAYS%) do (
set /A "YYYYMMDD=%JDNtoDate(JDN):JDN=number%, number+=1"
echo !YYYYMMDD:~4,2!/!YYYYMMDD:~6,2!/!YYYYMMDD:~0,4!
)
Thank you! I forgot about this thread. Good reading.