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-08-08 22:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to get the date N days earlier View 1,018 Replies 3
Original Poster Posted 2008-05-23 17:38 ·  中国 北京 联通
新手上路
Credits 10
Posts 3
Joined 2008-05-23 00:46
18-year member
UID 119452
Gender Male
Status Offline
If the current date returned by date is 2008-05-23, then under DOS how can I get the date N days earlier, for example 2 days earlier would be 2008-05-21
Floor 2 Posted 2008-05-24 15:01 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Does the DOS you mean refer to the DOS system or the CMD environment?
Floor 3 Posted 2008-05-26 15:29 ·  中国 广东 茂名 化州市 电信
中级用户
★★
Credits 396
Posts 183
Joined 2007-12-23 06:24
18-year member
UID 106531
Gender Male
Status Offline
@echo off
set a=%date:~0,4%
set b=%date:~5,2%
set/a c=%date:~8,2%-2
echo The date two days earlier is: %a% year %b% month %c% day
pause

If this solves it, give me some credits ah

[ Last edited by jiulong on 2008-5-26 at 09:03 PM ]
Floor 4 Posted 2008-05-30 15:04 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Originally posted by jiulong at 2008-5-26 03:29 PM:
@echo off
set a=%date:~0,4%
set b=%date:~5,2%
set/a c=%date:~8,2%-2
echo The date two days earlier is: %a% year %b% month %c% day
pause

If this solves it, give me some credits ah

[ Last edited by jiulong on 2008-5-26 at 09:03 PM ]


What date is two days before the 1st? The poster above, stop kidding around. Doing it like this will mislead us newbies, hehe, just joking~~ don't mind it

I suggest the OP search carefully, there are still quite a lot of posts with the answer, but calculating the date N days earlier is still rather complicated, leap months and all that (for me it's rather difficult too, I'm still learning as well)
無求一生光輝 唯朢鬥志不會斷
Forum Jump: