i'd like to use weekday to create directories and files, how can I use "sun"
"sat" "wed" and so on ... (or "lun" "mar" "mer" and so on, in my italian OS)
... it would be good also a weekday *number* (1, 2, 3, 4, 5, 6, 7)
but my problem is that i can't count on a stable system variable, as I know,
across systems (2000, XP, Vista, 2003...) and languages, I'd like to use the
same technique everywhere i can run a ".cmd" batch :-)
Have you any idea?
how can i do "SET weekday= something<---" ?
thanks for your kind attention
www.commandline.co.uk Look in the Batch function library for Date & Time
functions. Everything you need is there.
HTH
Matt
--
Posted via a free Usenet account from http://www.teranews.com
:: 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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
202569 Dec 23 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Http link format http://garbo.uwasa.fi/pub/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
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/> ; FI-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
>> how can i do "SET weekday= something<---" ?
>
> :: DateTime using WSH
> :: datetime.bat V4
thanx foxi, thanx matt!
Just for fun, a batch only solution which should work for any %date% format:
:: extract day month and year of the current date
@echo off
setlocal
:loop
set d="%date%"
echo.>_._
if not %d%=="%date%" goto :loop
for /f "tokens=1-3 delims=0123456789 " %%i in ("%date%") do set d=%%i%%j%%k
for /f "tokens=1-3 delims=%d% " %%i in ("%date%") do (
set /a d=1%%i
set /a m=1%%j
set /a y=1%%k)
if %d% gtr %m% (
set d=%m%
set m=%d%)
if %m% gtr %y% (
set m=%y%
set y=%m%)
if %d% gtr %m% (
set d=%m%
set m=%d%)
set /a d=%d%-100
set /a m=%m%-100
set /a y=%y%-10000
if %d% gtr 12 goto :exit
if %d% equ %m% goto :exit
if %m% gtr 12 (
set m=%d%
set d=%m%
goto :exit)
xcopy /l /d:%m%-%d%-%y% _._ \|find "_._"
if errorlevel 1 goto :l1
xcopy /l /d:%d%-%m%-%y% _._ \|find "_._"
if not errorlevel 1 goto :exit
:l1
(set m=%d%
set d=%m%)
:exit
del _._
set /a w=(%y%-1901)*365 + (%y%-1901)/4 + %d% + (!(%y% %% 4))*(!((%m%-3)^&16))
set /a w=(%w%+(%m%-1)*30+2*(!((%m%-7)^&16))-1+((65611044^>^>(2*%m%))^&3))%%7+1
if %w%==1 set w=Monday
if %w%==2 set w=Tuesday
if %w%==3 set w=Wednesday
if %w%==4 set w=Thursday
if %w%==5 set w=Friday
if %w%==6 set w=Saturday
if %w%==7 set w=Sunday
echo %y% %m% %d% %w%
Batch file using VBScript
::-----START-----
@Echo off & Setlocal
Set "_=%temp%\$_.vbs"
>"%_%" (Echo:Wscript.Echo^(WeekdayName^(Weekday^(Date^(^)^)^)^))
For /f %%# In ('cscript //nologo "%_%"') do set "DOW=%%#" & Del "%_%"
Echo:Day of Week variable, %%DOW%% is %DOW%
>Nul Ping -n 6 127.0.0.1
::------END------
Batch file using WMIC
::-----START-----
@Echo off & Setlocal
Set "_=Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
For /f "skip=1" %%# In ('WMIC Path Win32_LocalTime Get DayOfWeek') Do Set
DOW=%%#
For /f "tokens=%DOW%" %%# In ('Echo:%_%') Do Set DOW=%%#
Echo:Day of Week variable, %%DOW%% is %DOW%
>Nul Ping -n 6 127.0.0.1
::------END------
@if not exist %0 %0.bat
@goto doit
a100
mov ah,2A
int 21
mov ah,4C
int 21
g108
q
:doit
@debug <%0
@set /a daynum=%errorlevel%+1
for /f %%A in ('strftime +%%a') do set weekday=%%A
for /f %%A in ('strftime +%%u') do set weekday=%%A
for /f %%A in ('strftime +%%w') do set weekday=%%A
where strftime is date.exe from the GnuWin32 CoreUtils package
(<http://gnuwin32.sourceforge.net/packages/coreutils.htm>)renamed to
strftime.exe so as not to conflict with the Windows date utility. It does
pretty much what you would expect from a date utility and much, much more
- it has much of the formating capability of strftime() found in a wide
range of programming languages (it appears to be pretty much a wrapper for
the gcc strftime() function).
The first example sets to a day abreviation (since the LOCAL variable will
not be set on most machines, it is likely to default to English); the
second set weekday to a day number 1-7 with Monday as 1; the third is the
same except 0-6 with Sunday as 0.
For command line use, use % instead of %% in all three places it occurs in
each command.
--
T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
.
WSH should be installed on all of the systems listed by default.
@echo off
echo Wscript.Quit Weekday(Now)>tmp.vbs
cscript /nologo tmp.vbs
for %%i in (1 2 3 4 5 6 7) do if errorlevel %%i set dow=%%i
del tmp.vbs
echo dow=%dow%
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
thanks timo, Herbert, ten.nigriv, Esra, Ted Devis *and* Todd Vargo!
thanks you all!!! :-)
> @if not exist %0 %0.bat
> @goto doit
> a100
> mov ah,2A
> int 21
> mov ah,4C
> int 21
>
> g108
> q
>> doit
> @debug <%0
> @set /a daynum=%errorlevel%+1
this is very obscure to me Esra.
would you like to explain me this technique step by step?
anyway, this give me error (on win2000pro sp4) at the first two lines,
presented with a minus symbol
It's using a debug script to use "dos" int 21 to get the daynum (fn 2A)
in AL (where 0=Sunday) which is the returned by exiting with errorlevel
(fn 4C).
As you wanted sun=1, I simply added 1 back in the batch.
The first line is to ensure the batch is being run as "batchname.bat" so
that debug sees the whole filename
> anyway, this give me error (on win2000pro sp4) at the first two lines,
> presented with a minus symbol
Yes debug complains (but ignores) the first 2 lines.
I tested under XP pro (SP2)
Here it is again tidied up a bit
--------------------------
@echo off
@if not exist %0 %0.bat
@goto doit
a100
mov ah,2A
int 21
mov ah,4C
int 21
g108
q
:doit
debug <%0>nul
set /a daynum=%errorlevel%+1
echo daynum is %daynum%
--------------------------
*With* obscurity :-)
--------------------------
@echo off
@if not exist %0 %0.bat
@goto doit
e100 B4 2A CD 21 B4 4C CD 21
g
:doit
debug <%0>nul
set /a daynum=%errorlevel%+1
echo daynum is %daynum%
--------------------------
Herbert would probably do it all in 3 or 4 lines of ascii assembler!
> Herbert would probably do it all in 3 or 4 lines of ascii assembler!
my god
this is another world.
:-O
:-)
> *With* obscurity :-)
>
> --------------------------
> @echo off
> @if not exist %0 %0.bat
> @goto doit
> e100 B4 2A CD 21 B4 4C CD 21
> g
> :doit
> debug <%0>nul
> set /a daynum=%errorlevel%+1
> echo daynum is %daynum%
> --------------------------
>
> Herbert would probably do it all in 3 or 4 lines of ascii assembler!
As long a Microsoft doesn't change it's mind and add
16 bit support for 64 bit Windows, debug scripts and
ascii assembler has become pretty useless.