Computing.Net > Forums > Programming > date math in BAT, the ongoing saga

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

date math in BAT, the ongoing saga

Reply to Message Icon

Name: Mechanix2Go
Date: November 14, 2005 at 07:10:50 Pacific
OS: w2k sp3
CPU/Ram: PIII 933/256MB
Comment:

Hi gang,

This seems to work OK in w2k, but is hardwired for a %~tF output of:

14-11-05 21:34

It ignores the time HH:MM and uses only DD MM YY.

:: chk4age.bat
@echo off

if %1'==' echo we need YYMMDD && goto :eof

:main

set cutoff=%1
pushd test
for %%F in (*.bak) do call :compareDATE %%F
popd
goto :eof

:compareDATE

set origFMT=%~t1
set newFMT=%origFMT:~6,2%%origFMT:~3,2%%origFMT:~0,2%
if %cutoff% GTR %newFMT% echo older
:: DONE

Note that it will prompt for usage if a parameter is not given. But if you specify something off-the-wall it will not catch your mistake.



If at first you don't succeed, you're about average.

M2



Reply to Message Icon

Related Posts

See More


Font size in C++ Problem with redraw()



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Google Ads



Results for: date math in BAT, the ongoing saga

Batch - Time/Date calculator www.computing.net/answers/programming/batch-timedate-calculator/15453.html

making batchfile 4 yesterday's date www.computing.net/answers/programming/making-batchfile-4-yesterdays-date/16801.html

date math: the saga continues www.computing.net/answers/programming/date-math-the-saga-continues/16733.html