Simple batch file question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to script out a nightly chore on our servers, extracting
information from the SQL Server logs after it is backed up. Since the file is
generated every day, I'd like to make a new filename every time.

I looked at the %date% "function", which returns "Web 12/8/04". I would like
to modify this into "12-8-2004". I can't find anything about string handling
on the 'net, and I was wondering if anyone here could help.

Thanks!
 
change the separator in control panel-->regional settings-->customize-->date
 
Since sorting is done from left to right, a more meaningful file format would be
yyyymmdd. Here's a freeware utility that will rename the files in a date format
for you.

RenTS
http://www.xs4all.nl/~chi/utilities/rents.html

Here's an additional link that may be of interest to you:

DATE and TIME commands
http://www.robvanderwoude.com/datetime.html

And here's another site with a wealth of info on this subject. It's a little
hard to navigate. Best to use the Search engine under Tips & Tricks to find
articles about parsing date & time variables.

http://www.jsiinc.com/
 
Maury Markowitz said:
I'm trying to script out a nightly chore on our servers, extracting
information from the SQL Server logs after it is backed up. Since the file is
generated every day, I'd like to make a new filename every time.

I looked at the %date% "function", which returns "Web 12/8/04". I would like
to modify this into "12-8-2004". I can't find anything about string handling
on the 'net, and I was wondering if anyone here could help.

Thanks!

Try this:

@echo off
for /F "tokens=2" %%a in ('echo %date:/=-%') do set MyDate=%%a
echo The date is %MyDate%
 
Maybe this is sufficient ...

Open Control Panel / Regional Options / tab Date
Change Date separator to "-". click Apply and OK.

Check
Start a Command Prompt (or cmd at Start / Run).
Type echo %date%
Now you should get "Wed 12-8-04".
Couldn't get rid of "Wed" tho.

John7
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top