When managing servers, you often need to determine the log file of the day to be uploaded based on the system date. For example, you need to upload the log of last Friday on Monday, and upload the log of the previous day on other dates, log files are named by date. This requires obtaining the date of the first three days, or the date of the previous n days. Batch processing can be implemented in combination with vbs. The file is as follows.
If "% Date :~ 13% "=" 1 "(set daysago = 3) else (set daysago = 1)>" % Temp % \ mydate. vbs "Echo lastdate = Date ()-% daysago %>" % Temp % \ mydate. vbs "Echo fmtdate = right (Year (lastdate), 4) ^ & right (" 0 "^ & month (lastdate), 2) ^ & right ("0" ^ & Day (lastdate), 2)> "% Temp % \ mydate. vbs "Echo wscript. echo fmtdatefor/F % A in ('cscript/nologo "% Temp % \ mydate. vbs "') Do (set dstdate = % A) set dstdate = % dstdate :~ 0, 4%-% dstdate :~ 4,2%-% dstdate :~ 6, 2% echo % dstdate %
If it is Win8, you can set if "% Date :~ 13% "changed to if" % Date :~ 12%"
set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
Set the date format.