@ Echo off
Rem calculates the date before the specified number of days
Set daysago = 10
Rem assumes that the system date format is yyyy-mm-dd.
Call: datetodays % Date :~ 0, 4% % Date :~ 5, 2% % Date :~ 8, 2% passdays
Set/A passdays-= % daysago %
Call: daystodate % passdays % dstyear dstmonth dstday
Set dstdate = % dstyear %-% dstmonth %-% dstday %
Echo % daysago % day date is % dstdate %
Pause
Goto: EOF
: Datetodays % YY % mm % DD % days
Setlocal enableextensions
Set YY = % 1 & set Mm = % 2 & set dd = % 3
If 1% YY % LSS 200 if 1% YY % LSS 170 (set YY = 20% YY %) else (set YY = 19% YY %)
Set/a DD = 100% DD % 100, Mm = 100% mm % 100
Set/A z = 14-mm, Z/= 12, y = YY + 4800-z, M = mm + 12 * z-3, j = 153 * m + 2
Set/a j = J/5 + dd + y * 365 + Y/4-y/100 + Y/400-2472633
Endlocal & set % 4 = % J % & Goto: EOF
: Daystodate % days % YY mm dd
Setlocal enableextensions
Set/A = % 1 + 2472632, B = 4 * A + 3, B/= 146097, c =-B * 146097, C/= 4, C + =
Set/a d = 4 * C + 3, D/= 1461, E =-1461 * D, E/= 4, e + = C, M = 5 * E + 2, M/= 153, DD = 153 * m + 2, DD/= 5
Set/a DD =-dd + E + 1, Mm =-M/10, mm * = 12, mm + = m + 3, YY = B * 100 + d-4800 + M/10
(If % mm % LSS 10 set Mm = 0% mm %) & (if % DD % LSS 10 set dd = 0% DD %)
Endlocal & set % 2 = % YY % & set % 3 = % mm % & set % 4 = % DD % & Goto: EOF