I'm running into a dilemma. I want to send a preemptive email to users telling them that an upcoming task is about to happen. In order to do that I'm defining some variables, sending an email via blat, sleeping the batch for 5 minutes, then executing the rest of the script.
When executing %time%
at 4:00PM, I get 16:00:00.00. If I add 5 minutes to it, only for display purposes in the email with the following code:
@echo on
SET /a timeminute = 00 + 5 << --- test code
::SET /a timeminute = %time:~3,2% + 5 << --- actual code in GoLive
IF %timeminute% LEQ 9 (
GOTO :resetTime
) ELSE (
GOTO :end
)
:resetTime
SET timeminute = "0%timeminute%"
:end
echo %timeminute%
pause
I get 5, not 05 like expected. Using arithmetic on time drops leading zeros, so I try to add it back in later but the later SET is within the IF statement and cannot be seen? How can I see that? Is there a such thing as an environment variable in batch?
Keep in mind this issue only happens within the first 9 minute of the hour, after that time, there are no more leading zeros.
Bonus: What happens when the minutes in a hour is 55-59? In my example, it will be 60-64, so I need a way of rounding up an hour and take care of the remaining minutes. Right now, I see that as a bug, but I do not foresee this script running at those odd times. But if it is an easy fix please let me know as I have not even tried to tackle that problem.
Thank you kindly
A more compact form to do the same thing is this:
Answered my own question with the following: