Home > Batch File, Programming > Batch File ISO 8601 Date Format

Batch File ISO 8601 Date Format

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 (http://en.wikipedia.org/wiki/ISO_8601). 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
cls
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%
REM
echo %isodt%
echo %date%
echo %time%
Advertisements
Categories: Batch File, Programming
  1. No comments yet.
  1. 16th March, 2013 at 15:18

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: