[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Concatenate system date to a file

Hi Experts, currently I am scheduling a command-line zip task every midnight. I want to zip to the file with name as backup_yyyymmdd.zip where yyyymmdd is the system year, month and day. Please advice me on how could I achieve this using batch file command line.

1 Solution
The current date is in the environment variable %date%.
That comes in a rather unhandy format, as you can't use neither the slash nor does it have the correct sequence you want.
You can use a "for /f" command to do that; if necessary, depending on your date format, adjust the date delimiter used ("/") and the order in which the tokens are assigned:

for /f "tokens=1-3 delims=/" %%a in ("%date%") do (
  set mm=%%a
  set dd=%%b
  set yyyy=%%c
set BackupFile=backup_%yyyy%%mm%%dd%

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now