比较 Windows 批处理文件中的 2 个日期 [英] Compare 2 dates in a Windows batch file

查看:31
本文介绍了比较 Windows 批处理文件中的 2 个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较批处理文件中的 2 个日期?这:

How is it possible to compare 2 dates in batch files? This:

if %%newdate geq %olddate%  _do smth_

不起作用.

在这种情况下,我有
27.05.2013 大于 15.07.2013
14.07.2013 小于 15.07.2013

In this case I have that
27.05.2013 is greater than 15.07.2013 and
14.07.2013 is less than 15.07.2013

振亚

推荐答案

试试这个:

set "sdate1=%olddate:~-4%%olddate:~3,2%%olddate:~0,2%"
set "sdate2=%newdate:~-4%%newdate:~3,2%%newdate:~0,2%"
if %sdate1% GTR %sdate2% (goto there)  else echo here

这篇关于比较 Windows 批处理文件中的 2 个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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