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 15:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Give up, do not enter]About backtracking to any time View 2,265 Replies 32
Original Poster Posted 2008-06-01 21:58 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
&&Because of a brother's help request, I suddenly thought of writing a batch script (not using VBS) for arbitrary time backtracking. Because I knew that judging the time points of hours, minutes, days, months, and years would be quite complicated, I was mentally prepared at the beginning, but only when I was in the middle of writing did I really understand the difficulties here. The difficulty lies in how to convert and calculate the arbitrary time entered by others. For example, if you enter 0 0 0 0 100000 (meaning 100,000 minutes), how to convert it into the year, month, day, hour, and minute to backtrack. I racked my brains and still couldn't figure it out clearly. I hope everyone can sort out the ideas. Because the meaning of the problem is also difficult to describe clearly, I specially post my partial code below:

@echo off&color 1f&mode con lines=10&setlocal enabledelayedexpansion
title ***Time Backtracking Batch Script*** by cn-dos zw19750516
:begin
cls&echo.&echo ===============================================================================
echo Please enter the time to backtrack. Please enter it correctly in the format of year month day hour minute. If there is no value, please enter 0. Separate them with spaces in between. Do not pad 0 in front of the value. For example: 10 6 1 19 44 (10 years, 6 months, 1 day, 19 hours, 44 minutes), 0 0 0 0 400 (400 minutes). And 10 06 01 19 44 and 10 6 and 10 6 0 0 0 0 are all incorrect inputs.
echo ===============================================================================
echo.&set /p times=Please enter here:
echo %times: =%|findstr ""&&goto wrong
for %%i in (%times%) do (
set /a n+=1&set str=%%i
if "!str:~,1!" equ "0" goto wrong
)
if !n! neq 5 goto wrong
set n=0
for /f "tokens=1-5 delims= " %%a in ("%times%") do set /a ys=%%a,ms=%%b,ds=%%c,hs=%%d,mis=%%e
set /a y=%date:~,4%,m=100%date:~5,2%%%100,d=100%date:~8,2%%%100,mi=100%time:~3,2%%%100
if "%time:~,1%"=="" (set h=%time:~1,1%) else (set h=%time:~,2%)
set /a a=%y%%%4,b=%y%%%100,c=%y%%%400
if %c% equ 0 (set yun=A) else (if %a% equ 0 if %b% neq 0 set yun=A)
if defined yun (set n=29) else (set n=28)
set /a mi-=mis,h-=hs,d-=ds,m-=ms,h-=hs
............................
:wrong
cls&echo.&echo.&echo Incorrect value. Please enter correctly&ping /n 2 127.1>nul&goto begin


[ Last edited by zw19750516 on 2008-6-2 at 12:39 AM ]
批处理之家新域名:www.bathome.net
Floor 2 Posted 2008-06-01 22:17 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-06-01 22:20 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
My algorithm for this kind of problem is: first convert any given date into minutes (and if needed, also convert to seconds, hours, days), and then convert the minutes back into a date. You can refer to the functions in the function library --- timediff
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 4 Posted 2008-06-01 22:23 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
In fact, there are classic codes in the forum for backtracking days. Just judge the number of days in the time part.
致精致简!
Floor 5 Posted 2008-06-01 22:28 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Brothers, is it too simple? I've read all the forum-related posts and also discussed with namejm on QQ.
批处理之家新域名:www.bathome.net
Floor 6 Posted 2008-06-01 22:32 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
In fact, my original intention was to write a batch processing program for arbitrary time backtracking. As long as others input any set of five values in the input format of year, month, day, hour, and minute, they can get the backtracked year, month, day, hour, and minute. For example, input 0 0 0 100000 0 (100000 hours).
批处理之家新域名:www.bathome.net
Floor 7 Posted 2008-06-01 22:35 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Request zw19750516 brother to disclose his QQ number and namejm's QQ number ^_^
Floor 8 Posted 2008-06-01 22:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Provide an idea: First, convert the month, day, and time into the number of days. Then subtract the input year from the current year. Then subtract the converted number of days from the result. Finally, refine the time precisely.
致精致简!
Floor 9 Posted 2008-06-01 22:52 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
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-1 22:37:
Provide an idea
First, convert the month, day, time into days.
Then subtract the input year from the current year,
Then subtract the converted days from the result, and finally refine the time.

Thanks for your concern many times, brother. Please look at this set of values 20 34 600 4000 10000, going back 20 years, 34 months, 600 days, 4000 hours, 10000 minutes. I have an idea that is to calculate the time difference from the current system time to January 1, 00:00 of the first year of the AD as the number of minutes, then convert all the input time into the value counted in minutes, then subtract the input converted value from the system value, and then push forward the year, month, day, hour, minute from the reference value of January 1, 00:00 of the first year of the AD. The problem is that it is quite difficult to convert the input value into minutes. For example, how many minutes is 20 years =? and 34 months =?
批处理之家新域名:www.bathome.net
Floor 10 Posted 2008-06-01 22:55 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Passing by...

Still VBS is refreshing~~
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 11 Posted 2008-06-01 23:00 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
It really feels so difficult. Could it really be that batch processing can't solve this problem?
批处理之家新域名:www.bathome.net
Floor 12 Posted 2008-06-01 23:05 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Will it overflow
Also, why do I always get an error when running the above
What is the role of this P
简单!简单!再简单!
Floor 13 Posted 2008-06-01 23:11 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
If all are converted into minutes, it will be an extremely large number, and then it involves the problem of large number calculation.

In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes

As above, what does 2 months refer to? For example, if today is June 1st, is 2 months ago April 1st?

Or 2 months after the current time minus 600 days, 4000 hours, 10000 minutes?
致精致简!
Floor 14 Posted 2008-06-01 23:18 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
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-1 23:11:
If all are converted to minutes, it will be an extremely large number, which then involves the problem of large number calculation.
In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes
As above, what does 2 months refer to...

The five values 20, 34, 600, 4000, 10000 are all to be deduced through calculation, not simply subtraction of the same phase
批处理之家新域名:www.bathome.net
Floor 15 Posted 2008-06-01 23:19 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
If all are converted into minutes, it will be an extremely large number, which then involves the problem of large number calculation.
In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes
As above, what does 2 months refer to? For example, if today is June 1st, is 2 months ago April 1st?
Or is it 2 months after subtracting 600 days, 4000 hours, and 10000 minutes from the current time?

I think the building owner means: 20 years + 2 months + 600 days + 4000 hours + 10000 minutes

But it feels meaningless, and even............. alas
Forum Jump: