Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a thowback to the '80's I am using a batch script to log SOAP injections
The output file name is time stamped but it only works properly after 10:00!

echo on
echo %DATE%
echo %TIME%
set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetimef%


The difficulty is that I cannot find a good example that would suppress the space in the small hours or left pad it with zero.

e.g where '2013_03_06_ _8_16' would be represeted as either 2013_03_06_08_16' or 2013_03_06_8_16'

Currently I get '2013_03_06__'
Posted
Updated 5-Mar-13 21:46pm
v2

1 solution

You could extract the first character of the time value and if it's a space rebuild it with a leading zero. Something like (my .bat skills being rusty):
set Z=%time:~0,1%
if %Z% NEQ 0 set Z=0
set newtime=%Z%%time:~1,7%


Reviewing this I realise you need to check for the digits 1 and 2 also.
 
Share this answer
 
v3
Comments
Ger Hayden 7-Mar-13 3:55am    
This is waht I settled on - thanks for the steer:
<pre>
echo on
echo %DATE%
echo %TIME%
set Z=%time:~0,1%
ECHO FIRST TEST
if 1 NEQ %Z% ECHO GOTO NEQ1
GOTO TIMELABEL
:NEQ1
ECHO AT NEQ1
if 2 NEQ %Z% ECHO goto NEQ2
GOTO TIMELABEL
:NEQ2
ECHO AT NEQ2
SET Z=0
:TIMELABEL
set newtime=%Z%%time:~1,7%
echo %newtime%
</pre>
Richard MacCutchan 7-Mar-13 4:20am    
A slightly shorter version:

set Z=%TIME:~0,1%
if "1" EQU "%Z%" GOTO TIMELABEL
if "2" EQU "%Z%" GOTO TIMELABEL
SET Z=0
:TIMELABEL
set newtime=%Z%%TIME:~1,7%

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900