The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,978 other subscribers

Archive for August 4th, 2010

batch-file: Getting current yyyyMMdd date into an environment variable.

Posted by jpluimers on 2010/08/04

This seems to be a recurring question on a lot of forums:

How to get the current date as yyyyMMdd into environment variable datestring in a regional independent way?

A lot of solutions are using construct around the %date% environment variable similar to this:

for /f "usebackq tokens=1,2,3,4 delims=- " %%i in (`echo %date%`) do (
set datestring=%%l%%k%%j
echo %%i
echo %%j
echo %%k
echo %%l
echo %datestring%

There are two things wrong with this kind of solution:

  1. It depends on the order of fields inside the %date% environment variable
  2. It depends on the delimiter inside the %date% environment variable (specified by delims in the above example)

(note: the %date% environment variable has the same format as the date command).

For sytems having Powershell installed, this is a possible solution: Read the rest of this entry »

Posted in Power User | Leave a Comment »

%d bloggers like this: