![dos batch file time leading zeros dos batch file time leading zeros](https://worldtimetodays.com/wp-content/uploads/2022/06/georgia-investigation-could-result-trump-jail-akerman-390x220.jpg)
When time is between 0:01 to 9:59am, The Octal conversion section returns this error. Looks like you've saved me the bother! Thanks for posting your solution for others to share. Thanks eyahlin I've been meaning to look into this for a while, but as I don't use the original backup script any more I haven't got round to it.
![dos batch file time leading zeros dos batch file time leading zeros](https://assets.zerohedge.com/s3fs-public/styles/inline_image_mobile/public/inline-images/2022-06-16_05-53-09.jpg)
:: Tidy up SET START_TIME= SET END_TIME= SET START_TIMESTAMP= SET END_TIMESTAMP= SET ELAPSED_TIME= SET ELAPSED_HOURS= SET ELAPSED_MINUTES= SET ELAPSED_SECONDS= 4:29 am Anonymous said. ECHO Process took %ELAPSED_HOURS% hours, %ELAPSED_MINUTES% minutes, and %ELAPSED_SECONDS% seoonds. Hope this helps! off :: Clock in START_TIME set START_TIME=%TIME% :: Do process here! %* :: Clock in END_TIME set END_TIME=%TIME% :: Now that the timestamps are recorded, :: Fix possible bug where 08 and 09 are treated erroneously from octal conversion :: Set START_TIMESTAMP as the number of seconds so far today if %START_TIME:~0,1% EQU 0 (set /a START_TIMESTAMP=%START_TIME:~1,1%*3600) ELSE (set /a START_TIMESTAMP=%START_TIME:~0,2%*3600) if %START_TIME:~3,1% EQU 0 (set /a START_TIMESTAMP=%START_TIMESTAMP%+%START_TIME:~4,1%*60) ELSE (set /a START_TIMESTAMP=%START_TIMESTAMP%+%START_TIME:~3,2%*60) if %START_TIME:~6,1% EQU 0 (set /a START_TIMESTAMP=%START_TIMESTAMP%+%START_TIME:~7,1%) ELSE (set /a START_TIMESTAMP=%START_TIMESTAMP%+%START_TIME:~6,2%) :: Set END_TIMESTAMP as the number of seconds so far today if %END_TIME:~0,1% EQU 0 (set /a END_TIMESTAMP=%END_TIME:~1,1%*3600) ELSE (set /a END_TIMESTAMP=%END_TIME:~0,2%*3600) if %END_TIME:~3,1% EQU 0 (set /a END_TIMESTAMP=%END_TIMESTAMP%+%END_TIME:~4,1%*60) ELSE (set /a END_TIMESTAMP=%END_TIMESTAMP%+%END_TIME:~3,2%*60) if %END_TIME:~6,1% EQU 0 (set /a END_TIMESTAMP=%END_TIMESTAMP%+%END_TIME:~7,1%) ELSE (set /a END_TIMESTAMP=%END_TIMESTAMP%+%END_TIME:~6,2%) :: Work out the elapsed time expressed in seconds :: Do the correct calculation to account for roll-over :: (assumes the whole elapsed time is always less than 24 hours) IF %END_TIMESTAMP% GEQ %START_TIMESTAMP% ( SET /a ELAPSED_TIME=%END_TIMESTAMP% - %START_TIMESTAMP% ) ELSE ( :: ELSE IF %END_TIMESTAMP% LSS %START_TIMESTAMP% ( SET /a ELAPSED_TIME=%END_TIMESTAMP% + 86400 - %START_TIMESTAMP% ) :: Split elapsed time into hours, minutes and seconds SET /a ELAPSED_HOURS=%ELAPSED_TIME% / 3600 SET /a ELAPSED_MINUTES=(%ELAPSED_TIME% - (%ELAPSED_HOURS% * 3600)) / 60 SET /a ELAPSED_SECONDS=%ELAPSED_TIME% - (%ELAPSED_HOURS% * 3600) - (%ELAPSED_MINUTES% * 60) :: The following could be piped to a log file, if required echo. Hi! THANKS! This is grand! I picked up from where you left, fixed the octal conversion bug, and did some optimization tweaks. When that is true, the numeric variables are set to 0 instead of the time in seconds. This does not work if any of the digits in the time stamp are 08 or 09.
#Dos batch file time leading zeros windows#
However, above script failed to generate file if hour is less than 10 as it returns ‘ 8’ for example with leading space and Windows 2003 rejects file name with space.Does it work at e.g. Set timestamp=%year%%month%%day%%hour%%minute%%seconds% We suffixed data file name with timestamp to make it unique as below As a POC and to keep costs down, we decided to use windows batch file scripting to do this. Recently, we had requirement to generate unique file name to transfer data to another DC in an encrypted format from Windows 2003 server.