Last active
August 29, 2015 14:14
-
-
Save JohnLBevan/204a900b67ee1e2c16d1 to your computer and use it in GitHub Desktop.
Batch File Date Format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ::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