批量格式化文件日期YYYYMMDD [英] Format file date YYYYMMDD in batch

查看:105
本文介绍了批量格式化文件日期YYYYMMDD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理批处理文件中的一些代码,该代码评估两个文件的日期.如果一个日期大于另一个日期,则它将运行另一个蝙蝠文件.我想做的是将两个日期的格式设置为YYYYMMDD,以便可以使用GTR(大于).

I've been working on some code in a batch file that evaluates two file dates. If one date is greater than the other then it runs another bat file. What I want to do is format the two dates as YYYYMMDD so that I can use the GTR (greater than).

代码在下面,但是如果我使用==(等于),它可以工作,因为它正在评估字符串.我只想知道一个文件日期是否大于另一个文件日期.

The code is below but and it works if I use == (equal) because it's evaluating the string. I only want to know if one file date is greater than the other file date.

我不是要有人修改下面的代码,但是如果您能告诉我如何设置日期格式,我将不胜感激.

I'm not asking for someone to amend the code below but if you can show me how to format the dates I would be very grateful.

set Fileone=File1.txt
set FileTwo=File2.txt

pushd "D:\Board\Broadcast\FA_Report8_A"
FOR %%f IN (%FileOne%) DO SET filedatetime=%%~tf
FOR %%f IN (%FileTwo%) DO SET filedatetime2=%%~tf
SET filedatetime2=%year%%month%%day%
IF %filedatetime:~0, 10% GTR %filedatetime2:~0, 10% ( 
echo FileOne Greater - run bat
timeout /t 20 /nobreak
goto Finish
) else (
echo FileOne not Greater - Finish
goto Finish
)
:Finish
echo finished 
pause

推荐答案

在具有不同日期格式的计算机之间不能移植,但是最简单的方法是使用子字符串:%var:~STARTPOS,LENGTH%

It's not portable between machines with different date formats but the simplest way is to use a substring: %var:~STARTPOS,LENGTH%

set filedatetime=14/06/2012 12:26
set filedatetime=%filedatetime:~6,4%%filedatetime:~3,2%%filedatetime:~0,2%
echo "%filedatetime%"

"20120614"

这篇关于批量格式化文件日期YYYYMMDD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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