China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 17:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Give up, do not enter]About backtracking to any time View 2,266 Replies 32
Floor 31 Posted 2008-06-02 00:46 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by 26933062 at 2008-6-2 00:43:

Isn't this subtracting exactly 2 months?
First subtract the minutes, hours, and days, the result is: 19:09 on April 1, 2008
Then subtract 2 full months, that is: 4 minus 2, getting 19:09 on February 1, 2008

Please look at my calculation order. If you change the days to 10 days ago, it won't be subtracting exactly 2 months, right?
批处理之家新域名:www.bathome.net
Floor 32 Posted 2008-06-02 02:59 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Headache, not tested in detail

@echo off
set/p times=Enter year month day hour minute
for /f "tokens=1-5 delims= " %%a in ("%times%") do set /a yy=%%a,mm=%%b,tt=%%c,hh=%%d,ss=%%e
for /f "tokens=1-3 delims=-/\:. " %%i in ("%date%") do set /a p1=%%i,p2=100%%j%%100,p3=100%%k%%100
for /f "tokens=1-3 delims=:" %%i in ('time/t') do set /a t1=100%%i%%100,t2=100%%j%%100
set/a s2=ss%%60,t1-=ss/60%%24,t2-=s2,hh+=ss/60
if %t2% lss 0 set/a t2+=60
if %t1% lss 0 set/a t1+=24
set/a h1=hh%%24,tt+=(hh-h1)/24,t1-=h1
if %t1% lss 0 set/a t1+=24,tt+=1
set/a p1-=yy
set/a m2=mm%%12,p1-=(mm+p2)/12,p2-=m2
if %p2% leq 0 set/a p2+=12
if %p3% gtr %TT% goto ppp
:nxt
set/a p2-=1
if %p2% equ 0 set/a p1-=1&&set p2=12
set/a PN2="!(p1%%4) & !(!(p1%%100)) | !(p1%%400)",PN2=28+PN2
for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i
if %p3% leq %tt% goto nxt
:ppp
set/a p3=%p3%-%tt%
setlocal enabledelayedexpansion
for %%i in (p2 p3 t1 t2) do if !%%i! lss 10 set %%i=0!%%i!
echo %p1% year %p2% month %p3% day %t1% hour %t2% minute
pause&goto :eof
简单!简单!再简单!
Floor 33 Posted 2008-10-13 08:43 ·  中国 广东 深圳 电信
初级用户
★★
Credits 185
Posts 88
Joined 2008-05-12 18:46
18-year member
UID 118511
Gender Male
Status Offline
Having the courage to try is a good thing!!
Forum Jump: