Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: batch DOS
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 5-Mar-13 22:18pm
Ger Hayden26.1K
Edited 5-Mar-13 22:46pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3
Comments
Ger Hayden at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 6 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100