Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save JohnLBevan/204a900b67ee1e2c16d1 to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/204a900b67ee1e2c16d1 to your computer and use it in GitHub Desktop.
Batch File Date Format
::See http://www.robvanderwoude.com/datetimentparse.php for lots of useful info on dates in batch files.
::The script below assumes a locale of UK (i.e. %date% gives DD/MM/YYYY).
@echo off
::Split date & time into component parts; assumes dd/mm/yyyy
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%A IN ('echo %Date%') DO (SET dd=%%A&SET mm=%%B&SET yyyy=%%C)
FOR /F "TOKENS=1,2,3 DELIMS=:. " %%A IN ('echo %Time%') DO (SET hh=%%A&SET mi=%%B&SET ss=%%C)
::join in order of greatest affector to least (i.e. a year is longer than a month, so comes first)
SET strDateTime=%yyyy%%mm%%dd%%hh%%mi%%ss%
::output result
echo %strDateTime%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment