mmddyy
I then need to use that in a file name(.zip)
for example if today is 7/5/2007, then I need a variable that produces
"A070407.zip"
How can I do this?
PLEASE HELP!
http://groups.google.com/group/alt.msdos.batch/msg/8c267951d6988661
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
for /f "tokens=1-3 delims=/" %%a in ("%yesterday%") do (
set mm=%%a
set dd=%%b
set yy=%%c)
echo %mm%/%dd%/%yy:~-2% & DEL tmp.vbs
Ras-
Thank you for your help too. I did make sense of your script. It was
helpful and I understand the parsing that you are doing, except I
don't understand why there are spaces. for example the date is
showing 07 05 07 vs 070507. Do you know why?
thanks
>Ras-
>Thank you for your help too. I did make sense of your script. It was
>helpful and I understand the parsing that you are doing, except I
>don't understand why there are spaces. for example the date is
>showing 07 05 07 vs 070507. Do you know why?
Try this:
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
for /f "tokens=1-3 delims=/" %%a in ("%yesterday%") do (
set "mm=%%a"
set "dd=%%b"
set "yy=%%c"
)
if "%mm:~1,1%"=="" set mm=0%mm%
echo %yy:~-2%/%mm%/%dd%& DEL tmp.vbs
yymmdd is a good format for sorting by date on a PC so alter that if you
need to.
>Ras-
>Thank you for your help too. I did make sense of your script. It was
>helpful and I understand the parsing that you are doing, except I
>don't understand why there are spaces. for example the date is
>showing 07 05 07 vs 070507. Do you know why?
I made a boo boo with the date segments and this might be locale dependant.
This works here (with WSH giving d/mm/yyyy)
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
for /f "tokens=1-3 delims=/" %%a in ("%yesterday%") do (
set "dd=%%a"
set "mm=%%b"
set "yy=%%c"
)
if "%dd:~1,1%"=="" set dd=0%dd%
echo %yy:~-2%/%mm%/%dd%& DEL tmp.vbs
And here is another script with more options:
:: DateTime using WSH
:: datetime.bat V4
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This uses Windows Scripting Host to set variables
:: to the current date/time/day/day_number
:: for Win9x/ME/NT/W2K/XP etc
:: Thanks go to Todd Vargo for his scripting
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
set TmpFile="%temp%.\tmp.vbs"
echo> %TmpFile% n=Now
echo>>%TmpFile% With WScript
echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
echo>>%TmpFile% .Echo "set yr=" + Right(Year(n),2)
echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
echo>>%TmpFile% .Echo "set day=" + Right(100+Day(n),2)
echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
echo>>%TmpFile% .Echo "set min=" + Right(100+Minute(n),2)
echo>>%TmpFile% .Echo "set sec=" + Right(100+Second(n),2)
echo>>%TmpFile% .Echo "set dow=" + WeekDayName(Weekday(n),1)
echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
echo>>%TmpFile% End With
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
call "%temp%.\tmp.bat"
del "%temp%.\tmp.bat"
del %TmpFile%
set TmpFile=
set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%
echo The year (YYyy) is "%year%"
echo The year (yy) is "%yr%"
echo The month is "%month%"
echo The day (%dow%) is "%day%"
echo The full weekday name is "%dow2%"
echo.
echo ISO 8601 Day-Of-Week number is "%iso%"
echo.
echo The hour is "%hour%"
echo The minute is "%min%"
echo The second is "%sec%"
echo.
echo The date and time stamp is "%stamp%"
echo.
echo time (hhmmss) (%hour%%min%%sec%)
echo.
echo date A (yyyymmdd) (%year%%month%%day%)
echo date B (mmddyyyy) (%month%%day%%year%)
echo date C (ddmmyyyy) (%day%%month%%year%)
echo.
echo date D [yymmdd] [%yr%%month%%day%]
echo date E [mmddyy] [%month%%day%%yr%]
echo date F [ddmmyy] [%day%%month%%yr%]
:: datetime.bat
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I agree with your yymmdd naming convention, except I'm trying to
download a file named sMMDDYY.zip (s070507.zip).
I modified your code to this.....
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
for /f "tokens=1-3 delims=/" %%a in ("%yesterday%") do (
set "mm=%%a"
set "dd=%%b"
set "yy=%%c"
)
if "%mm:~1,1%"=="" set mm=0%mm%
echo %mm%%dd%%yy:~-2%& DEL tmp.vbs
yet, I still get a weird result. I get 07 507 vs 070507. Do you know
why?
thanks!
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
for /f "tokens=1-3 delims=/" %%a in ("%yesterday%") do (
set "mm=%%a"
set "dd=%%b"
set "yy=%%c"
)
if "%mm:~1,1%"=="" set mm=0%mm%
if "%dd:~1,1%"=="" set dd=0%dd%
>I need to make a variable in a batch file that will take the previous
>days date and format it to:
>
>mmddyy
>
>I then need to use that in a file name(.zip)
>
>for example if today is 7/5/2007, then I need a variable that produces
>"A070407.zip"
Rather a bad example, with D=Y.
That format (FFF) does not comply with ISO 8601.
NOWMINUS, via sig line 3, could generate its components, and will
generate the logical and standard YYMMDD in envvar with
NOWMINUS f1 j0 b3 Eenvvar
For later use in off-topic systems such as NT & XP, see NOWMINUS.TXT.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
> mmddyy
> I then need to use that in a file name(.zip)
*** XSET can alter date formats and place that format into a variable.
There are also utilities that can alter and do calculations to dates. One
that comes to mind is FDATE.
One or more links to these can be found in my "DOS Websites" Directory
at:
http://www.chebucto.ca/~ak621/DOS/Websites.html
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/