Linked Questions

Popular Questions

Batch file to create a folder based on current date & time

Asked by At

we have a simple batch file that creates a backup of a folder and appends the date & time to the end.

We use this incrementally and it outputs a folder such as "data 28-04-13".

I would like to add the time to the end of this, however my code outputs time as HH:MM, which is not valid for a folder name as it includes a colon (:).

Please could someone modify my code to remove the :, or replace it with a ".".

Thank You

@echo off & for /F "tokens=1-4 delims=/ " %%A in ('date/t') do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C

@echo off & for /F "tokens=1-4 delims=/ " %%D in ('time/t') do (
set DateTime=%%D

set CurrentDate=%DateDay%-%DateMonth%-%DateYear%-%DateTime%

md "F:\MobilePC\data %CurrentDate"

Answered my own question

So, this was the easiest way for me:

set CurrentDate=%DateDay%-%DateMonth%-%DateYear%-%time:~0,2%.%time:~3,2%

Which outputs "31-10-13-11.35"

Related Questions