Archive for November, 2012

Batch File ISO 8601 Date Format

18th November, 2012 1 comment

UPDATED: See Batch File ISO 8601 Date Format – Version 2.0

The following batch file creates a variable to hold the date and time in ISO 8601 date format ( It’s dependant on the way the date and time is presented based on the locale of the system, so it may need to be modified for machines outside of the UK.

Additionally, I’ve noticed that if the time is before 10:00 am, then the hour does not have a leading zero – this could have an impact if you wanted to use this to name a file, for example.

@echo off
echo Get the current date and time in YYYY-MM-DD-HH-MM-SS format
SET isodt=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
echo %isodt%
echo %date%
echo %time%
Categories: Batch File, Programming