Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Format vs Local 1

Status
Not open for further replies.

tekdudedude

Technical User
Sep 29, 2007
79
Hello,

In batch files I routinely use these commands to get DATE and TIME vars
Code:
set YYYY=%DATE:~10,4%
set MO=%DATE:~4,2%
set DD=%DATE:~7,2%
set HH=%TIME:~0,2%
set MM=%TIME:~3,2%
set SS=%TIME:~6,2%
set DOW=%DATE:~0,3%

The problem I am having is that from system-to-system the locale (via the Regional & Language Options) are different which effect getting HH. The default (problem) is that I get a one digit hour. I need to always get a two digit hour (08 rather than 8 for 08:00 AM). Resetting the locale on all the systems is not an option.

How can I set the current hour to a variable (HH) so as it uses two digits reguardless of the system locale settings?

Thanks,

TD
 
Hey All,

For those in the same situation, I found a simple work around.

After closer examination I found that the results returned by %TIME% and time /t are not the same...in a good way.

%TIME% returns the locale TIME format while time /t returns the hour (HH in above post) in two digits. This being so one can do the following:
Code:
time /t > %TMP%\time.txt
set /p TIME1="" < %TMP%\time.txt
set HH=%TIME1:~0,2%
set MM=%TIME1:~3,2%

Enjoy,

TD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top