How to Use batch file writing: Get the day before the current date

Source: Internet
Author: User

Http://bbs.csdn.net/topics/310231544

Test. bat

[Code = batchfile] @ echo off
Rem calculates the date before the specified number of days
Set daysago = 1
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
[/Code]

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.