copy foo.txt foo_YYYYMMDD.txt
where YYYYMMDD is the current date.
I am using Windows XP.
I happen to be working on a batch file that includes the logic you
need. Go figure :-)
===================
:: Get current date
for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do set CurrDate=%%c%
%a%%b
copy foo.txt foo_%CurrDate%.txt
===================
#1 FAQ - read Timo's FAQ - posted weekly, last posted Sep 22 @1159am (and
hence overdue - I've never figured out whether the date/time shown as "sent"
is UTC, local or local-with-daylight-saving-adjustment or even sender's or
receiver's view...)
The major issue is the date-format being used by the user running your file.
The format returned by date/t is set up by the USER settings, so it's not
consistent. Each user can set up a date format to optionally include dayname
or leading zeroes, have 2 or 4 digit year numbers, have different
element-sequences or have different separators.
Without knowing precisely the format you are using and whether or not it's
for your own use or for use in a commercial - even international -
environment, it's dangerous to make a simple suggestion like one that
assumes separator, element-sequence and element-presence.
Best to look at the FAQ for a guide - it covers most situations.
Ah, our crontab process must have been down. Anyway (for the OP)
1} How to get today's date elements into environment variables?
http://www.netikka.net/tsneti/info/tscmd001.htm
Also in the FAQ e.g.
6} How does one get yesterday's date?
31} How many days ago was 31.12.2003? What date was it 100 days ago?
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
REM get MM, DD and YYYY independent of system date format settings
echo Wscript.echo ^(DatePart^("YYYY", Date^)^)>DateYear.vbs
echo Wscript.echo ^(DatePart^("M", Date^)^)>DateMonth.vbs
echo Wscript.echo ^(DatePart^("D", Date^)^)>DateDay.vbs
for /f %%A in ('DateYear.vbs //nologo') do set /a yyyy=%%A
for /f %%A in ('DateMonth.vbs //nologo') do set /a mm=%%A
for /f %%A in ('DateDay.vbs //nologo') do set /a dd=%%A
del DateYear.vbs
del DateMonth.vbs
del DateDay.vbs
REM add leading zero to single digit numbers
if %mm% LSS 10 set mm=0%mm%
if %dd% LSS 10 set dd=0%dd%
If you insist on using DatePart, then you could produce your output all in
one go!
::----- START -----
>%temp%\_$.vbs (Echo:DateString=DatePart^("yyyy",Date^) ^& Right^(^
"0" ^& DatePart^("m",Date^),2^) ^&Right^("0" ^&DatePart^("d",Date^),2^)
Echo:Wscript.Echo DateString)
For /f %%# In ('cscript //nologo %Temp%\_$.vbs') Do (Set D_=%%#&&Del
%temp%\_$.vbs)
::------ END ------
The usual two spaces have preceeded each new line in order to highlight
line wrap!
> If you insist on using DatePart, then you could produce your output all in
> one go!
Yours is more concise, sure, but I reckon mine is easier for somebody
to fool around with Lego-fashion if they are more familiar with batch
than with wsh.
Yeah, sometimes dense code is difficult to decipher.
Here's another option:
:: DateTime - WMIC
@echo off
:: info based on usenet post by ten.n...@virgin.net
:: 18 Aug 2008 22:29:38 +0100,
:: xp and higher
(
Wmic Path Win32_LocalTime Get day,hour,minute,month,second,year /value
)>%temp%.\wmicinfo.txt
for /f "delims=" %%a in ('type %temp%.\wmicinfo.txt') do set %%a
del %temp%.\wmicinfo.txt
set Day=00%day%
set Hour=00%hour%
set Minute=00%minute%
set Month=00%month%
set Second=00%second%
set Day=%day:~-2%
set Hour=%hour:~-2%
set Minute=%minute:~-2%
set Month=%month:~-2%
set Second=%second:~-2%
set yr=%year:~2%
echo Hour=%hour%
echo Minute=%minute%
echo Second=%second%
echo Day=%day%
echo Month=%month%
echo Year=%year%
echo Yr=%yr%
pause
Or reduced for the purposes of this exercise:
::----- START -----
@Echo off&Setlocal
Set "_=%temp%\_$.tmp"
Wmic /output:%_% Path Win32_LocalTime Get Day,Month,Year /value
For /f "tokens=1-2 delims==" %%A In (
'Find "="^<%_%^&del %_%') Do (If %%B Lss 10 (Set %%A=0%%B) Else (Set
%%A=%%B))
Echo:Copy foo.txt foo_%Year%%Month%%Day%.txt&Pause
::------ END ------
> #1 FAQ - read Timo's FAQ - posted weekly, last posted Sep 22 @1159am (and
> hence overdue - I've never figured out whether the date/time shown as "sent"
> is UTC, local or local-with-daylight-saving-adjustment or even sender's or
> receiver's view...)
Read the actual headers of a few articles, using your regular system,
and including one of your own posted at a known local clock time, and
you'll soon work it out. Especially if you know where you are and the
relevant relationships between local times and UTC. Omphalocentric
systems stamp their local time, with offset.
Timo probably uses a CRON job to post while he's asleep. Many use
PST, even in Summer. Read the beginning of "- And he built a crooked
house -".
NOWMINUS, via sig line 3, programs directory, will do most Gregorian
date-setting jobs (not in Vista-64?).
--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|
if you have Services for Unix from Microsoft
date "+%Y%m%d"
(snip)
between local times and UTC. Omphalocentric
> systems stamp their local time, with offset.
What the 'hey' is Omphalocentric?
Coined a word have you Sir Stockton?
Actually "omphaloenteric". And yes, it is a genuine word. A medical
dictionary will tell you more about it.
This is just a guess but John might be preparing to purchase one of these
Oompa-Loompa outfits.
http://www.amazon.com/Charlie-Chocolate-Factory-Adults-Costume/dp/B000TMM7KU
Omphalocentric = Overly introspective and inclined to navel-gazing
>
> Actually "omphaloenteric". And yes, it is a genuine word. A medical
> dictionary will tell you more about it.
>
Omphaloenteric = Relating to the umbilicus and the intestine
Either way, how does that have anything to do with how systems handle
local time, daylight saving time and offsets? Color me confused...
--
Zaphod
Zaphod's just zis guy, ya know?
No : actually omphalocentric. I use it more, but not completely, in the
literal sense. Moderate-sized dictionaries don't necessarily have it,
but the Web does.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Usenet News services are currently unreliable; I may not see all articles here.