Technical Article

Format a DOS date as yyyymmdd

,

Do you run jobs that call BAT files where you wish you could include a formatted date stamp in the output name of an OSQL file? Well, you can using the DOS 'FOR' command. I named a variable FILEDATE and use it as:

path\Filename_%FILEDATE%.txt

(Note: A BAT file requires double %% in the 'FOR' command in order to work.)

REM Command line example:
For /F "tokens=2-4 delims=/ " %a IN ('Date /T') Do Set FILEDATE=%c%a%b

Echo %FILEDATE%


REM BAT File example:
For /F "tokens=2-4 delims=/ " %%a IN ('Date /T') Do Set FILEDATE=%%c%%a%%b

Echo %FILEDATE%

Rate

4.5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

4.5 (2)

You rated this post out of 5. Change rating