-2

Need urgent help on batch script, I'm trying to print the time format as below

C:\>time
The current time is:  0:08:22.96    

expectation : yyyyMMddHHmmSS = 20210522000000
Actual : yyyyMMddHHmmSS = 20210522 00000

Script used is :

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=1-3 delims=/:" %%a in ("%TIME%") do (set mytime=%%a)
set dt=%mydate%%mytime%0000
echo yyyyMMddHHmmSS = %dt%

Kindly suggest on how to achieve this in a batch script.

  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer May 21 '21 at 20:52
  • Thanks @halfer I got the solution. I used this `For /f "tokens=1-2 delims=/: " %%a in ("%TIME%") do (if %%a LSS 10 (set mytime=0%%a) else (set mytime=%%a) )`. – kiran kumar May 22 '21 at 04:05

0 Answers0