Obtain the date of the first three days of the system date using batchcompute bat

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.