Windows Batch File (.bat) to get current date in MMDDYYYY format.

Home -> Programming

104714 views

From the computer of: seamonkey420 (132 recipes)
Created: Jul 24, 2005


12 comments:
View all comments

Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

This is a recipe I discovered while working on a few old skool dos batch files. This is a quick .bat file to create a folder based on the current date however, this sets it up in the MMDDYYYY format. Useful for those .bat scripters who need to use the current date variable in such a format.

Just copy and paste the text in quotes to a text file. Then rename file test.bat and run from command line to see (echo is on by default).

This can be used in a very powerful way, the FOR command can be reused and changed to query to see if a file exists and then if so create the folder, etc.

for now, lets start basic...

Quote:

echo on
@REM Seamonkey's quick date batch (MMDDYYYY format)
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%


this does nothing but setup the %date variable to be todays date in MMDDYYYY format so it can be called later in the script, etc..

peace
seamonkey420

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.




12 Recipe comments: View comments

Windows Batch File (.bat) to get current date in MMDDYYYY fo by wattpuppy
Re: Windows Batch File (.bat) to get current date in MMDDYYY by wanderer
Re: Windows Batch File (.bat) to get current date in MMDDYYY by wanderer
Re: Windows Batch File (.bat) to get current date in MMDDYYYY fo by wattpuppy
Re: Windows Batch File (.bat) to get current date in MMDDYYYY fo by wanderer
Subtract dates by Anonymous
Re: Windows Batch File (.bat) to get current date in MMDDYYYY fo by Anonymous
subtract date from current date by Anonymous
Re: Subtract dates by davak
Script a date then count up days by sfortine
mod this for different date output by dklock
time and date in batch file by SparkByte



Related recipes:

  PHP: Print the current year for copyright notices
  Subversion: See the Latest Repository Revision Number
  AS3: How to Convert Number to String
  Java: Decimal Format to Easily Create Custom Output
  csh/C shell scripts: for loop syntax
  Bourne/bash shell script for loop syntax
  Determine if a file is readable by current Bourne shell script user
  Load an Icon from an Embedded Resource in .NET
  A simple script that waits for a process to complete and then executes a command
  Configure Subversion Client to Ignore Certain Files

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.