The Wiert Corner – irregular stream of stuff

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

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140417-Windows-8.1-Update-says-it-failed-but-it-succeeded

    20140417-Windows-8.1-Update-says-it-failed-but-it-succeeded--Windows-Help-and-Support--cannot-find-any-info--how-surprising-it-never-does

    20140329-VMware-vSphere-Client-4.1-retry-with-compatibility-settings

    More Photos
  • Pages

  • All categories

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

    Join 1,251 other followers

Archive for August 4th, 2010

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

Posted by Jeroen Pluimers 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 »

 
Follow

Get every new post delivered to your Inbox.

Join 1,251 other followers

%d bloggers like this: