I am trying to run a batch file, which runs an XSLT transformation against an XML file and writes out a second XML file.
This XML filename is determined by the following line in the batch file:
When the time has a leading space (that is, any time before 10:00 am), the variable %TIME:~3,2% returns a result with a leading space, which causes the filename to be truncated. The result file is empty.If I run the batch after 10:00am, everything works fine. How can I generate a value similar to %TIME:~3,2% that works before 10:00am? |
||||
7 Answers
This will solve the space in the name issue, and replace it with a zero so it sorts correctly in a list.
|
|||||
|
How about this one ?
The locale here is german, so you might have to adjust the order in "set cpdate..." for your needs. |
|||||||||
|
Setting a variable for the hour value as follows solves the problem for me:
FOR /F "tokens=* delims= " %%a IN ("%TIME:~0,2%") DO SET hour=%%a |
|||||||||||||||||||||
|
(This is an old question but this answer could be of help for somebody else.)
Using %time: =% gets rid of the spaces in the time variable.
Example:
You could save the time variable to another using this method and then work from that one:
|
|||
I use a simple trick to do this:
|
|||
REM This .bat script gives you a parameter timetext with a zero instead of a space
|
||||
This maybe more helpful in Dos Batch ~~ try this
|
IF %TIME% < 10
add a 0 to the front (or remove if you need to)? If not you could try adding something before the time to force it to stay there. – David Starkey May 6 '13 at 15:15%TIME:~0,2%
expression, and this is what is causing the error. This makes a lot more sense, because the value for the month is 05 right now, and that works fine. – Chad Dybdahl May 6 '13 at 16:08