Windows Batch Script - Parsing Date Into Components (Month, Day, Year)

Last Modified: Fri, 26 Sep 2008 23:15:00 +0000 ; Created: Fri, 26 Sep 2008 23:15:00 +0000

I found a U.S. locale specific way to parse a date into components inside a Windows batch script (.bat or .cmd).

@REM Valid only for U.S. (English) locale
FOR /F "tokens=2-4 delims=/ " %%i IN ('echo %date%') DO SET MONTH=%%i& SET DAY=%%j& SET YEAR=%%k

Again it only works for the U.S. locale (and similiar). If you need something that works regardless of locale there are other examples that do it in a batch script, but you should really consider an external .com or .exe that inserts it into your batch script (Google it) or use a Windows Scripting Host script instead.