Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: tonysathre
I've seen a lot of people ask for batch scripts to can perform time/date calculations. I found this cool little command-line utility that will allow you to do this:
TimeMath.exe /?
Version 0.91, Copyright (C)2001, Frank P. Westlake.
Performs addition, subtraction, or comparison on a date, time, or both.[command | ] TIMEMATH [date] [time] [+|-date] [+|-time] [unit+|-#] [options]
["test[date] [time]"]command Any of the parameters may be piped in.
date A date to use as the basis of addition, subtraction or comparison.
Format: [YY]YY.MM[.DD] or [YY]YY-MM[-DD] or MM/DD/[YY]YY
time A time to use as the basis of addition, subtraction or comparison.
Format: HH:MM[:SS[.MSS]] or H:MMa or H:MMp
+|-date A date to add to or subtract from 'date' above.
Format: +Y.M.D or +Y-M-D or -Y.M.D or -Y-M-D
+|-time A time to add to or subtract from 'time' above.
Format: +HH:MM[:SS[.MSS]] or -HH:MM[:SS[.MSS]]
"test[date] [time]" A date and/or time to compare with 'date' and/or 'time'.
Format: "test[YYYY.MM.DD] [HH:MM[:SS[.MSS]]]]"
where 'test' is one of <, =, ==, >, <=, or >=.
UNITS (keyword may be replaced by the uppercase letter):
Year Adjust years by +|- #.
mOnth Adjust months by +|- #.
Day Adjust days by +|- #.
Hour. Adjust hours by +|- #.
Minute Adjust minutes by +|- #.
Second Adjust seconds by +|- #.
mIllisecond Adjust milliseconds by +|- #. Note: 'ms' may be used instead.
OPTIONS:
system Use system time (UTC). Ignores 'date' and 'time' if present.
local Use local time (default). Ignores 'date' and 'time' if present.
dateonly Print only the date portion of the result.
timeonly Print only the time portion of the result.
RETURN CODES (ERRORLEVEL):
0 Successful calculation or TRUE comparison.
1 'date' and 'time' out of bounds or FALSE comparison.
2 Calculation out of bounds (time & day).
3 Calculation out of bounds (year & month).The default output is:
Date Time Weekday JulianDate Week#(Sunday based) Week#(Monday based)
2001.08.31 17:02:51.363 Friday J243 S34 M35This program fails if the result is greater than 30828.09.14 02:48:05.477
or less than 1601.01.01 00:00:00.000. Quotation marks must enclose the
comparison parameter. 'dateonly' and 'timeonly' may both be used to suppress
the remainder of the output string.EXAMPLES:
TimeMath 15:36:13.056 -1:36:13.056
TimeMath 15:36:13.056 h-1 m-36 s-13 ms-056
TimeMath 15:36:13.056 hour-1 minute-36 second-13 millisecond-056
TimeMath year+1 day-40
FOR /F "tokens=4" %A IN ('TimeMath') DO @Echo Julian Date=%A
FOR /F %A IN ('DIR C:\pagefile.sys^|TimeMath week+1') DO Set Reboot=%A
TimeMath "=%Reboot%"&&Echo Reboot.
TimeMath 2001.09.02 18:04:39.692 ">2001.09.01 10:01:01.920"
TimeMath system "<20:00"
"Computer security." — Oxymoron

Pretty cool.
Many have spent much effort on 'date math' in BATs. It's just about not worth the hassle.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

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