Link to home
Start Free TrialLog in
Avatar of James Cochrane
James CochraneFlag for United States of America

asked on

Need to format the current date to YYYYMMDD

I have a batch file that is going to be called automatically.  It looks for a file that will have the current date as part of the file name.  I need a DOS script that can take the current date, transform it to the format YYYYMMDD and then append that to the base of the file name in order to process the file.  As an example, the base of the file name is ABC- so the script needs to get the current date and append it as follows:

ABC-20110923.csv

I have been trouble finding information on how to do that.

Thanks for your help.
SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The "easy" way as shown involving %date% is difficult when using different machines, OS's or logins as the format changes.  VBScript will work the same every time.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Which proves my point :-)
Avatar of Bill Prew
Bill Prew

Steve's article has some great approaches to this.  

I'll just add that I often use a tiny free utility called DOFF for this which can be found at:

http://www.jfitz.com/dos/index.html#DOFF

If that's any interest to you and you have questions let me know.

~bp