cmd脚本中的日期算术 [英] Date arithmetic in cmd scripting

查看:166
本文介绍了cmd脚本中的日期算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本,将文件名从aDate.txt更改为bDate.txt,其中:

I need to write a script to change a filename from aDate.txt to bDate.txt where:


  • aDate是当前的系统日期为 yyyymmdd 格式,

  • bDate是当前的系统日期 - yyyymmdd 格式的

  • aDate is the current system date in yyyymmdd format and
  • bDate is the current system date - 1 in yyyymmdd format.

我目前有:

set yy=%date:~6,2%
set mm=%date:~3,2%
set dd=%date:~0,2%
if "%date:~6,1%"==" " set yy=0%yy:~1,1%
if "%date:~3,1%"==" " set mm=0%mm:~1,1%
if "%date:~0,1%"==" " set dd=0%dd:~1,1%
SET sys_date=20%yy%%mm%%dd%
ECHO %sys_date%
REM still have to do this bit properly
SET sys_date_yesterday=%sys_date%a
move %sys_date%.txt %sys_date_yesterday%.txt

但我不知道如何做日期-1事情(除了长风)从一天减去1,如果这是= 0然后从月份减去一个,并将day =设置为新月的最后一天,依此类推。多年。

but I have no idea how to do the date -1 thing (other than the long winded) subtract 1 from the day and if that is = 0 then subtract one from the month and set the day = to the last day of the new month and so on for years.

任何想法?

推荐答案

这也可以:

http://www.robvanderwoude.com/datetiment.php#Yesterday

它非常完整,它检查注册表中的本地日期格式设置,并在创建昨天的日期时使用。

It is very complete in that it checks the registry for local date format settings and uses those when creating the yesterday date.

这篇关于cmd脚本中的日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆