Computing.Net > Forums > Programming > Batch - Time/Date calculator

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch - Time/Date calculator

Reply to Message Icon

Name: tonysathre
Date: June 13, 2007 at 16:23:42 Pacific
OS: Windows XP Pro SP2
CPU/Ram: P4 2.60 Ghz\ 768 MB
Product: Dell Dimension 4550
Comment:

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:

Download Here

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 M35

This 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



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: June 13, 2007 at 21:20:44 Pacific
Reply:

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



0
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: Batch - Time/Date calculator

Date Calculations in KSH www.computing.net/answers/programming/date-calculations-in-ksh/4022.html

Batch File - date and time on files www.computing.net/answers/programming/batch-file-date-and-time-on-files/9137.html

Passing prior date into a variable www.computing.net/answers/programming/passing-prior-date-into-a-variable/15571.html