Discussion:
Time and Date, day and day number in a batch file
(too old to reply)
foxidrive
2007-05-23 16:08:20 UTC
Permalink
What is the difference between %iso% and %iso2%?
I dunno - that was Dr John's handiwork.
Note, the %amp% is a pretty good trick but CStr(Year(n)) would save a lot of
typing by replacing all instances of %amp% with a +. The lines using the
Right function are converted to strings automatically so do not need CStr
Simpler is a good thing in my book, Todd, so thanks for those pointers.
Here's an updated version, from V3 to V4



:: 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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Jon
2007-05-23 16:43:28 UTC
Permalink
Thanks to all!! I'm new to making complex batch files, so if someone
could help me connect the dots, I'd appreciate it. I actually do need
the full day of the week in the command.

So it needs to look like this: xcopy /Y c:\folder\<DOW>\<DOW>file.abc \
\10.10.10.13\Share

for example:

xcopy /Y c:\folder\Monday\Mondayfile.abc \\10.10.10.13\Share
Todd Vargo
2007-05-23 17:39:33 UTC
Permalink
Post by Jon
Thanks to all!! I'm new to making complex batch files, so if someone
could help me connect the dots, I'd appreciate it. I actually do need
the full day of the week in the command.
So it needs to look like this: xcopy /Y c:\folder\<DOW>\<DOW>file.abc \
\10.10.10.13\Share
xcopy /Y c:\folder\Monday\Mondayfile.abc \\10.10.10.13\Share
Please run the datetime.bat v4 in the post you replied to.

%dow2% provides the full day of the week.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Jon
2007-05-23 16:43:43 UTC
Permalink
Thanks to all!! I'm new to making complex batch files, so if someone
could help me connect the dots, I'd appreciate it. I actually do need
the full day of the week in the command.

So it needs to look like this: xcopy /Y c:\folder\<DOW>\<DOW>file.abc \
\10.10.10.13\Share

for example:

xcopy /Y c:\folder\Monday\Mondayfile.abc \\10.10.10.13\Share
Jon
2007-05-23 16:43:56 UTC
Permalink
Thanks to all!! I'm new to making complex batch files, so if someone
could help me connect the dots, I'd appreciate it. I actually do need
the full day of the week in the command.

So it needs to look like this: xcopy /Y c:\folder\<DOW>\<DOW>file.abc \
\10.10.10.13\Share

for example:

xcopy /Y c:\folder\Monday\Mondayfile.abc \\10.10.10.13\Share
Jon
2007-05-23 16:44:50 UTC
Permalink
Thanks to all!! I'm new to making complex batch files, so if someone
could help me connect the dots, I'd appreciate it. I actually do need
the full day of the week in the command.

So it needs to look like this: xcopy /Y c:\folder\<DOW>\<DOW>file.abc \
\10.10.10.13\Share

for example:

xcopy /Y c:\folder\Monday\Mondayfile.abc \\10.10.10.13\Share
Dr J R Stockton
2007-05-23 18:51:55 UTC
Permalink
Post by foxidrive
What is the difference between %iso% and %iso2%?
I dunno - that was Dr John's handiwork.
echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
The first requires no major function call, but relies on the coding of a
Date as a float daycount from 1899-12-30 00:00:00 local. (Int looks like
a function; but it may be done more directly, as in some other languages
IIRC).

The second requires a function call but does not rely on the
representation of a date.

The results should be the same.

Ideally, ISO year-week-day would also be provided, but without using
DatePart.
--
(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.
sKurt
2007-10-01 03:49:03 UTC
Permalink
Post by foxidrive
Simpler is a good thing in my book, Todd, so thanks for those
pointers. Here's an updated version, from V3 to V4
:: 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
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)

i.e.

01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31



--
sKurt
2007-10-01 05:09:07 UTC
Permalink
Post by sKurt
Post by foxidrive
:: 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
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant

12/31/2007 = DAY OF YEAR 365



--
Todd Vargo
2007-10-01 05:22:18 UTC
Permalink
Post by sKurt
Post by sKurt
Post by foxidrive
:: 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
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
LOL, I just posted VBScript code to do just that. I leave it as an exercise
for you to wrap it into your multi-OS batch code.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
sKurt
2007-10-01 13:56:21 UTC
Permalink
Post by Todd Vargo
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
LOL, I just posted VBScript code to do just that. I leave it as an
exercise for you to wrap it into your multi-OS batch code.
Always on the ball even before there is a game! Thanks Todd


sKurt

--
sKurt
2007-10-01 14:16:20 UTC
Permalink
Post by Todd Vargo
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
LOL, I just posted VBScript code to do just that. I leave it as an
exercise for you to wrap it into your multi-OS batch code.
Hmmm... Is part of the exercise finding the code? ;)

didn't see where you posted it just yet.

sKurt
--
Todd Vargo
2007-10-01 21:00:17 UTC
Permalink
Post by sKurt
Post by Todd Vargo
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
LOL, I just posted VBScript code to do just that. I leave it as an
exercise for you to wrap it into your multi-OS batch code.
Hmmm... Is part of the exercise finding the code? ;)
didn't see where you posted it just yet.
See my post to your "Convert Date to a Number" thread.
http://tinyurl.com/2ahvw5
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
sKurt
2007-10-01 21:58:13 UTC
Permalink
Post by Todd Vargo
Post by sKurt
Hmmm... Is part of the exercise finding the code? ;)
didn't see where you posted it just yet.
See my post to your "Convert Date to a Number" thread.
http://tinyurl.com/2ahvw5
oops, maybe it should have been part of the exercise! :-O

Thanks I'll see what I can do with that


sKurt

--
billious
2007-10-01 06:31:09 UTC
Permalink
Post by sKurt
Post by sKurt
Post by foxidrive
:: 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
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
--
----- batch begins -------
[1]::days.bat
[2]:: de luxe version to accomodate XP 'date/t' breakages
[3]:: NT/2K/XP required
[4]:: version 3.02
[5]:: set dd, mm, yy, yyyy, yyyymmdd to today - n
[6]:: dow to day-of-week (1=Sun..7=Sat)
[7]:: doy to day-of-year (1..365 or 366)
[8]:: julian as yyddd (numeric - leading-zero suppressed)
[9]:: julian_text as yyddd (with leading 0 padding to 5 characters)
[10]:: ibm_julian as yyyyddd
[11]:: since as days since 01/01/1901
[12]:: dayname as name of day
[13]:: day as 3-character abbreviation thereof
[14]:: dd, mm, yy in leading-zero-filled format
[15]:: first parameter is number of days, n - default is 1
[16]:: second parameter is date - default is today
[17]
[18]@echo off
[19]for %%u in (dd mm yy yyyy) do set %%u=
[20]set daysoff=%1
[21]if not defined daysoff set daysoff=1
[22]set zt$=echo %2
[23]if "%2"=="" set zt$=date/t
[24]for /f "tokens=1,2,3,4 delims=/-. " %%w in ('%zt$%') do call :getdate
%%w %%x %%y %%z
[25]::dd,mm - suppress leading zero
[26]set /a dd=1%dd% - 100
[27]set /a mm=1%mm% - 100
[28]:negloop
[29]if /i %daysoff%==0 goto final
[30]if %daysoff% LSS 0 set /a yyyy=%yyyy%+4&set/a
daysoff=%daysoff%+1461&goto negloop
[31]set /a daysoff=daysoff - 1
[32]
[33]:SET30
[34]set /A dd=%dd% - 1
[35]if %dd% GTR 0 goto DONE
[36]:: else last day of month - assume 31
[37]set dd=31
[38]set /A mm=%mm% - 1
[39]if %mm% GTR 0 goto SETDAY
[40]:: Must be Dec. 31st
[41]set /A mm=12
[42]set /A yyyy=%yyyy% - 1
[43]goto DONE
[44]
[45]:SETDAY
[46]::Problem months are Feb, Apr,Jun,Sep and Nov
[47]if %mm%==4 goto SET30
[48]if %mm%==6 goto SET30
[49]if %mm%==9 goto SET30
[50]if %mm%==11 goto SET30
[51]if not %mm%==2 goto DONE
[52]:: February - default to 28 days (exception for leap years)
[53]set /A dd=%yyyy% %% 4
[54]if not %dd%==0 goto set28
[55]set /A dd=%yyyy% %% 100
[56]if not %dd%==0 goto set29
[57]set /A dd=%yyyy% %% 400
[58]if not %dd%==0 goto set28
[59]
[60]:set29
[61]set dd=29
[62]goto done
[63]
[64]:SET28
[65]set dd=28
[66]
[67]:DONE
[68]if /i %daysoff%==0 goto final
[69]if %dd% GTR %daysoff% goto thismonth
[70]set /a daysoff=%daysoff% - %dd%
[71]set dd=1
[72]goto set30
[73]
[74]:thismonth
[75]set /a dd=%dd% - %daysoff%
[76]
[77]:final
[78]:: now convert back to 2-digit dd, mm and yy
[79]if %mm% LSS 10 set mm=0%mm%
[80]if %dd% LSS 10 set dd=0%dd%
[81]set yy=%yyyy:~2,2%
[82]:: calculate day-of-week, day-of-year
[83]:: get (y mod 4) * 12 + m
[84]set daysoff=0,31,59,90,120,151,181,212,243,273,304,334
[85]set /a dow=1%mm% - 100
[86]for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set /a doy=%%a +
1%dd% - 100
[87]set /a dow=%yyyy% %% 4
[88]set /a dow=%dow% * 12 + 1%mm% - 100
[89]set
daysoff=0,31,60,91,121,152,182,213,244,274,305,335,366,397,425,456,486,517,547,578,609,639,670,700
[90]if %dow% GTR 24 set
daysoff=731,762,790,821,851,882,912,943,974,1004,1035,1065,1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
[91]if %dow% GTR 24 set /a dow=%dow% - 24
[92]for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set zt$=%%a
[93]set /a daysoff=%yyyy% / 4
[94]set /a daysoff=%daysoff% * 1461
[95]set /a dow=1%dd% - 96 + %daysoff% + %zt$%
[96]set /a dow=%dow% %%7 + 1
[97]for /f "tokens=%dow% delims=," %%a in
("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday") do set
dayname=%%a
[98]set day=%dayname:~0,3%
[99]set /a zt$=%yyyy% %% 4
[100]if %zt$%==0 if 1%mm% GTR 102 set /a doy=%doy% + 1
[101]set /a julian=1%yy% - 100
[102]set /a julian=%julian% * 1000 + %doy%
[103]set /a julian_text=100000 + %julian%
[104]set julian_text=%julian_text:~1%
[105]set ibm_julian=%yyyy%%julian_text:~2%
[106]:: since 01/01/1901
[107]set /a zt$=%yyyy% - 1901
[108]set /a daysoff=%zt$% / 4
[109]set /a since=365 * %zt$% + %daysoff% + %doy% - 1
[110]for %%i in (zt$ daysoff) do set %%i=
[111]set yyyymmdd=%yyyy%%mm%%dd%
[112]::ECHO %YYYY%%MM%%DD%
[113]GOTO :eof
[114]
[115]:: from the four date components passed, determine the date
[116]:getdate
[117]set dd=%2&set mm=%3&set yy=%4
[118]:: if XP, dayname may be missing
[119]if not defined yy set dd=%1&set mm=%2&set yy=%3
[120]:: if yy-mm-dd format, switch dd & yy
[121]echo.|date|find "(y">nul
[122]if not errorlevel 1 set %yyyy%=%dd%&set%dd%=%yy%&set%yy%=%yyyy%
[123]:: if mm-dd-yy format, switch dd & mm
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set %yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy%
[126]:: Now process month names for XP
[127]for %%Z in (01Jan 02Feb 03Mar 04Apr 05May 06Jun 07Jul 08Aug 09Sep 10Oct
11Nov 12Dec) do call :procmth %%Z
[128]:: Ensure dd and mm have leading 0s if required
[129]set yyyy=%dd:~1%
[130]if not defined yyyy set dd=0%dd%
[131]set yyyy=%mm:~1%
[132]if not defined yyyy set mm=0%mm%
[133]set yyyy=%yy:~1%
[134]if not defined yyyy set yy=0%yy%
[135]:: Ensure yy is 2-digit and yyyy 4-digit
[136]set yyyy=%yy:~2%
[137]if defined yyyy set yyyy=%yy%&goto setyy
[138]:: yy is 2-digit
[139]set yyyy=20%yy%
[140]if %yyyy% GEQ 2080 set yyyy=19%yy%
[141]:setyy
[142]set yy=%yyyy:~2%
[143]goto :eof
[144]
[145]:procmth
[146]set yyyymmdd=%mm:~0,3%
[147]set yyyy=%1
[148]set yyyy=%yyyy:~2%
[149]if /i %yyyy% NEQ %yyyymmdd% goto :eof
[150]set mm=%1
[151]set mm=%mm:~0,2%
[152]goto :eof
[153]
[154]::days.bat ends
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof
sKurt
2007-10-01 14:15:17 UTC
Permalink
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
Lines start [number] - any lines not starting [number] have been
wrapped and should be rejoined. The [number] that starts the line
should be removed
The label :eof is defined in NT+ to be end-of-file but MUST be
expressed as :eof
Thanks, I will give this a try!

sKurt

--
sKurt
2007-10-01 18:36:49 UTC
Permalink
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set %yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy%
[126]:: Now process month names for XP
I ran the code and got the error at line 125

it gives me

if not errorlevel 1 set =10 & set10-01 & set01=

the syntax of the command is incorrect.
'set10' is not recognized as an internal....
'set01' is not recognized as an internal....

Thanks!

sKurt



--
billious
2007-10-02 04:09:03 UTC
Permalink
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set %yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy%
[126]:: Now process month names for XP
I ran the code and got the error at line 125
it gives me
if not errorlevel 1 set =10 & set10-01 & set01=
the syntax of the command is incorrect.
'set10' is not recognized as an internal....
'set01' is not recognized as an internal....
Thanks!
sKurt
Yes - there's an error in that line - one of the traps of playing with
date-formats



[120]:: if yy-mm-dd format, switch dd & yy
[121]echo.|date|find "(y">nul
[122]if not errorlevel 1 set yyyy=%dd%&set dd=%yy%&set yy=%yyyy%
[123]:: if mm-dd-yy format, switch dd & mm
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set yyyy=%dd%&set dd=%mm%&set mm=%yyyy%

Note changes in lines [122,125] - "set %varname%" becomes "set varname"

Note that this routine was originally designed (a number of years ago) to
calculate "yesterday" for NT4 and was then modified to add "a number of days
away from today" and then "a number of days away from a specified date" and
fixed for XP changes

Consequently, by default (with no parameters) the results should be
YESTERDAY's date-data; to get TODAY's data, supply a parameter of 0

And of course it only deals with English-language configurations.
sKurt
2007-10-02 17:20:47 UTC
Permalink
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year
number, I >>> > would be in heaven ;)
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set
%yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy% [126]:: Now process month
names for XP
I ran the code and got the error at line 125
And of course it only deals with English-language configurations.
Line 149 gives me;

if /I Jan NEQ ~0 3 goto :eof

'3' is not recognized as an internal or external command.

;)


if I run the program with command line 0 the last message is

set yyyymmdd=20070102



and if I run the program with no command line the last message is

set yyyymmdd=20070101

Thanks

sKurt

--
billious
2007-10-03 00:50:39 UTC
Permalink
Post by sKurt
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year
number, I >>> > would be in heaven ;)
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set
%yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy% [126]:: Now process month
names for XP
I ran the code and got the error at line 125
And of course it only deals with English-language configurations.
Line 149 gives me;
if /I Jan NEQ ~0 3 goto :eof
'3' is not recognized as an internal or external command.
;)
if I run the program with command line 0 the last message is
set yyyymmdd=20070102
and if I run the program with no command line the last message is
set yyyymmdd=20070101
Thanks
sKurt
--
I suspect you've heroically re-typed this batch.

The easy way is to cut-and-paste to a text file and either manually remove
the leading "[number]" or apply a simple? command like

for /f "tokens=2*delims=]" %i in ( ' find /v /n "" ^<filename.txt ' ) do set
yfl=%j&if defined yfl (echo %j>>filename.bat) else (echo\>>filename.bat)

which should re-constitute the batch.

As to the problem - I suspect that you've got an error on [146] where either
the line has been mistyped or the value of mm which should at that time
contain the month digits is incorrect. This is backed up by your report that
the final calculated month reported (presumably by un-commenting [112]) is
incorrect, although you'd observe that the day number appears to be right
(again, as I type, it's Oct 3rd locally - so my results are likely to be
different from yours.)

I could get a similar result by either
1) changing "mm" to "m" in [146]
or
2) installing [145a] set mm=
to artificially clobber the value of mm

So - if you could pm me or post a trace of the appropriate section by adding
[118a]@echo on
[125a]@echo off

then we could resolve the issue.
sKurt
2007-10-03 01:14:39 UTC
Permalink
Post by sKurt
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
Now if you could make this work with the Day of the Year
number, I >>> > would be in heaven ;)
Post by sKurt
Post by billious
Post by sKurt
Post by sKurt
i.e.
01/01/2007 = DAY OF YEAR = 1
12/31/2007 = DAY OF YEAR = 31
oops, I meant
12/31/2007 = DAY OF YEAR 365
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set
%yyyy%=%dd%&set%dd%=%mm%&set%mm%=%yyyy% [126]:: Now process
month >>> > names for XP
Post by sKurt
Post by sKurt
I ran the code and got the error at line 125
And of course it only deals with English-language configurations.
Line 149 gives me;
if /I Jan NEQ ~0 3 goto :eof
'3' is not recognized as an internal or external command.
;)
if I run the program with command line 0 the last message is
set yyyymmdd=20070102
and if I run the program with no command line the last message is
set yyyymmdd=20070101
Thanks
sKurt
--
I suspect you've heroically re-typed this batch.
The easy way is to cut-and-paste to a text file and either manually
remove the leading "[number]" or apply a simple? command like
for /f "tokens=2*delims=]" %i in ( ' find /v /n "" ^<filename.txt ' )
do set yfl=%j&if defined yfl (echo %j>>filename.bat) else
(echo\>>filename.bat)
which should re-constitute the batch.
As to the problem - I suspect that you've got an error on [146] where
either the line has been mistyped or the value of mm which should at
that time contain the month digits is incorrect. This is backed up by
your report that the final calculated month reported (presumably by
un-commenting [112]) is incorrect, although you'd observe that the
day number appears to be right (again, as I type, it's Oct 3rd
locally - so my results are likely to be different from yours.)
I could get a similar result by either
1) changing "mm" to "m" in [146]
or
2) installing [145a] set mm=
to artificially clobber the value of mm
So - if you could pm me or post a trace of the appropriate section by
then we could resolve the issue.
Actually, I do know how to cut n paste ;) And I manually removed the
[###} from the beginning of each line and I still have a copy of the
original so that if I goofed on the removal I would be able to
reference it back.

and I run it with echo off and use WinXP's scroll bar to run back to
start.


give me a sec to turn on the other PC with the code and I'll upload
what I am using


sKurt
--
Todd Vargo
2007-10-03 02:26:14 UTC
Permalink
Post by sKurt
Post by billious
I suspect you've heroically re-typed this batch.
The easy way is to cut-and-paste to a text file and either manually
remove the leading "[number]" or apply a simple? command like
for /f "tokens=2*delims=]" %i in ( ' find /v /n "" ^<filename.txt ' )
do set yfl=%j&if defined yfl (echo %j>>filename.bat) else
(echo\>>filename.bat)
which should re-constitute the batch.
As to the problem - I suspect that you've got an error on [146] where
either the line has been mistyped or the value of mm which should at
that time contain the month digits is incorrect. This is backed up by
your report that the final calculated month reported (presumably by
un-commenting [112]) is incorrect, although you'd observe that the
day number appears to be right (again, as I type, it's Oct 3rd
locally - so my results are likely to be different from yours.)
I could get a similar result by either
1) changing "mm" to "m" in [146]
or
2) installing [145a] set mm=
to artificially clobber the value of mm
So - if you could pm me or post a trace of the appropriate section by
then we could resolve the issue.
Actually, I do know how to cut n paste ;) And I manually removed the
[###} from the beginning of each line and I still have a copy of the
original so that if I goofed on the removal I would be able to
reference it back.
and I run it with echo off and use WinXP's scroll bar to run back to
start.
give me a sec to turn on the other PC with the code and I'll upload
what I am using
Oh my! Why go to so much effort when the code in question is NT/2K/XP
specific? Your original post indicated you are using 98 and XP systems.
ISTM, if you are going to move toward separate batch routines for each OS,
then it would be appropriate to drop the crossposting and resolve the code
for each OS separately in the appropriate groups. OTOH, as I alluded in your
"Convert Date to a Number" thread, http://tinyurl.com/2ahvw5 VBScript is
available on Windows 98 and newer systems, which can provide a multi-OS
solution with much less effort.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
sKurt
2007-10-03 03:09:01 UTC
Permalink
Post by Todd Vargo
Post by sKurt
Post by billious
I suspect you've heroically re-typed this batch.
The easy way is to cut-and-paste to a text file and either
manually remove the leading "[number]" or apply a simple? command
like
for /f "tokens=2*delims=]" %i in ( ' find /v /n "" ^<filename.txt
' ) do set yfl=%j&if defined yfl (echo %j>>filename.bat) else
(echo\>>filename.bat)
which should re-constitute the batch.
As to the problem - I suspect that you've got an error on [146]
where either the line has been mistyped or the value of mm which
should at that time contain the month digits is incorrect. This
is backed up by your report that the final calculated month
reported (presumably by un-commenting [112]) is incorrect,
although you'd observe that the day number appears to be right
(again, as I type, it's Oct 3rd locally - so my results are
likely to be different from yours.)
I could get a similar result by either
1) changing "mm" to "m" in [146]
or
2) installing [145a] set mm=
to artificially clobber the value of mm
So - if you could pm me or post a trace of the appropriate
then we could resolve the issue.
Actually, I do know how to cut n paste ;) And I manually removed
the [###} from the beginning of each line and I still have a copy
of the original so that if I goofed on the removal I would be able
to reference it back.
and I run it with echo off and use WinXP's scroll bar to run back to
start.
give me a sec to turn on the other PC with the code and I'll upload
what I am using
Oh my! Why go to so much effort when the code in question is NT/2K/XP
specific? Your original post indicated you are using 98 and XP
systems. ISTM, if you are going to move toward separate batch
routines for each OS, then it would be appropriate to drop the
crossposting and resolve the code for each OS separately in the
appropriate groups. OTOH, as I alluded in your "Convert Date to a
Number" thread, http://tinyurl.com/2ahvw5 VBScript is available on
Windows 98 and newer systems, which can provide a multi-OS solution
with much less effort.
You are very right Todd, and as mentioned before I will probably use
your code as it seems to fit all the requirements, but I am always
willing to learn new code and save it away for a rainy day. :)
Besides, I can still learn from reading/using the code for another
project.

I understand this is a winxp only type of code and can't really use it
here, however he went to a lot of trouble to put it together and as
long as I have the snip, perhaps a few more tweaks will make it work
fully and I can offer it to someone who may need it or I may need it in
the future so I am ready to see all comers on the question asked
originally

The .vbs solution, the gawk solution and the fdate.exe solution are all
very workable ways to solve the problem. Originally I was looking for
a true batch solution, so I didn't have to upload more files to the
sites, however, I found I was using an old version of gawk 2.15 rather
than 3.1.3 and then a newer verson of SED and as long as I am sending
up these I may as well send up the fdate as long as I am at it.

Mostly it is about the learning for me. I scan the net, read the posts,
examine code and if I ask a question I usually have scour'd the net for
some way to do it before I ask here because I hate to seem like I
haven't done my homework before I hit this site hat in hand ;)


I am sure if I sent you the now massive batch file you could change it
from 5000 lines to 1000 lines (or 1000 lines without comments into 250
lines) but I have fun looking for how to do things, kinda like a puzzle.

Thanks for the help and offers of help, it is really appreciated!

sKurt



--
Todd Vargo
2007-10-04 02:53:16 UTC
Permalink
Post by sKurt
Post by Todd Vargo
Oh my! Why go to so much effort when the code in question is NT/2K/XP
specific? Your original post indicated you are using 98 and XP
systems. ISTM, if you are going to move toward separate batch
routines for each OS, then it would be appropriate to drop the
crossposting and resolve the code for each OS separately in the
appropriate groups. OTOH, as I alluded in your "Convert Date to a
Number" thread, http://tinyurl.com/2ahvw5 VBScript is available on
Windows 98 and newer systems, which can provide a multi-OS solution
with much less effort.
You are very right Todd, and as mentioned before I will probably use
your code as it seems to fit all the requirements, but I am always
willing to learn new code and save it away for a rainy day. :)
Besides, I can still learn from reading/using the code for another
project.
I understand this is a winxp only type of code and can't really use it
here, however he went to a lot of trouble to put it together and as
long as I have the snip, perhaps a few more tweaks will make it work
fully and I can offer it to someone who may need it or I may need it in
the future so I am ready to see all comers on the question asked
originally
The .vbs solution, the gawk solution and the fdate.exe solution are all
very workable ways to solve the problem. Originally I was looking for
a true batch solution, so I didn't have to upload more files to the
sites, however, I found I was using an old version of gawk 2.15 rather
than 3.1.3 and then a newer verson of SED and as long as I am sending
up these I may as well send up the fdate as long as I am at it.
Mostly it is about the learning for me. I scan the net, read the posts,
examine code and if I ask a question I usually have scour'd the net for
some way to do it before I ask here because I hate to seem like I
haven't done my homework before I hit this site hat in hand ;)
I am sure if I sent you the now massive batch file you could change it
from 5000 lines to 1000 lines (or 1000 lines without comments into 250
lines) but I have fun looking for how to do things, kinda like a puzzle.
Thanks for the help and offers of help, it is really appreciated!
My main point was that this solution excluded support for 98 systems and
thus you will end up reinventing the wheel to accommodate the 98 systems
also. I presented a partial solution to your puzzle allowing you to work
with it a bit and learn from your efforts.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
sKurt
2007-10-04 06:45:42 UTC
Permalink
Post by Todd Vargo
Post by sKurt
I am sure if I sent you the now massive batch file you could change
it from 5000 lines to 1000 lines (or 1000 lines without comments
into 250 lines) but I have fun looking for how to do things, kinda
like a puzzle.
Thanks for the help and offers of help, it is really appreciated!
My main point was that this solution excluded support for 98 systems
and thus you will end up reinventing the wheel to accommodate the 98
systems also. I presented a partial solution to your puzzle allowing
you to work with it a bit and learn from your efforts.
And quite well I might add!

I am at the point where I have cleared up a lot of extra duplicate code
that because this started as a lets do this, to can we add this, to
massive un-orginized code that I tamed a great deal more. You and
everyone else who are kind enough to be of assistance when not just me
needs it, but to everyone who crys out for help.

I also learned from all the other hints and suggestions as well.

cheers

sKurt
--

billious
2007-10-03 05:30:52 UTC
Permalink
[]
Post by Todd Vargo
Oh my! Why go to so much effort when the code in question is NT/2K/XP
specific? Your original post indicated you are using 98 and XP systems.
ISTM, if you are going to move toward separate batch routines for each OS,
then it would be appropriate to drop the crossposting and resolve the code
for each OS separately in the appropriate groups. OTOH, as I alluded in your
"Convert Date to a Number" thread, http://tinyurl.com/2ahvw5 VBScript is
available on Windows 98 and newer systems, which can provide a multi-OS
solution with much less effort.
--
Todd Vargo
Ah, Glasshoppah!

It seems the QBASIC Kid is beginning to learn about appropriateness of
newgroups and languages :)

My attitude is that alt.msdos.batch is for DOS/9x batch solutions, and
alt.msdos.batch.nt for NT-class batch solutions. If you need both, then the
appropriate place is the group dealing with the LEAST capable language as,
with well-known exceptions, the earlier language is a subset of the later -
and a batch that works in the earlier should work in the later, albeit with
adjustments.

Hence, if the question is asked in ...nt, an NT-class solution is sought.
DOS/9x solution requirements are rare, and the majority of traffic in
alt.msdos.batch is actually seeking NT enlightenment. There should be no
need for cross-posting.

The next question is "what is batch?" which has been mulled over many, many
times. There are specific groups for qbasic, vbs, sed, (g)awk, other
scripting platforms and assembler. Within ...batch.. groups, a solution that
relies solely on the batch commandset is appropriate and on-topic. If the
problem cannot be solved using that command-set then by all means go ahead
and use another toolkit - the object is after all to solve the problem, not
indulge in a demarcation dispute. BUT - it is IMHO inappropriate to
mechanically attempt to solve what has been presented as a batch problem
with those other tools as a first choice.

I have established and executed batch jobs as part of COBOL routines. I
would not claim that they are COBOL, so I'm puzzled why some people try to
claim that vbs (etc) routines are "batch." They are not - they are merely
being invoked from the command-line processor.
Todd Vargo
2007-10-04 02:01:53 UTC
Permalink
Post by billious
[]
Post by Todd Vargo
Oh my! Why go to so much effort when the code in question is NT/2K/XP
specific? Your original post indicated you are using 98 and XP systems.
ISTM, if you are going to move toward separate batch routines for each OS,
then it would be appropriate to drop the crossposting and resolve the code
for each OS separately in the appropriate groups. OTOH, as I alluded in your
"Convert Date to a Number" thread, http://tinyurl.com/2ahvw5 VBScript is
available on Windows 98 and newer systems, which can provide a multi-OS
solution with much less effort.
--
Todd Vargo
Ah, Glasshoppah!
It seems the QBASIC Kid is beginning to learn about appropriateness of
newgroups and languages :)
My attitude is that alt.msdos.batch is for DOS/9x batch solutions, and
alt.msdos.batch.nt for NT-class batch solutions. If you need both, then the
appropriate place is the group dealing with the LEAST capable language as,
with well-known exceptions, the earlier language is a subset of the later -
and a batch that works in the earlier should work in the later, albeit with
adjustments.
Hence, if the question is asked in ...nt, an NT-class solution is sought.
DOS/9x solution requirements are rare, and the majority of traffic in
alt.msdos.batch is actually seeking NT enlightenment. There should be no
need for cross-posting.
The next question is "what is batch?" which has been mulled over many, many
times. There are specific groups for qbasic, vbs, sed, (g)awk, other
scripting platforms and assembler. Within ...batch.. groups, a solution that
relies solely on the batch commandset is appropriate and on-topic. If the
problem cannot be solved using that command-set then by all means go ahead
and use another toolkit - the object is after all to solve the problem, not
indulge in a demarcation dispute. BUT - it is IMHO inappropriate to
mechanically attempt to solve what has been presented as a batch problem
with those other tools as a first choice.
I have established and executed batch jobs as part of COBOL routines. I
would not claim that they are COBOL, so I'm puzzled why some people try to
claim that vbs (etc) routines are "batch." They are not - they are merely
being invoked from the command-line processor.
Hmm, my point to OP went way over your head and you seem to have an ax to
grind with me. Take your churlish remarks and go fishing somewhere else.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
billious
2007-10-04 02:31:54 UTC
Permalink
Post by Todd Vargo
Hmm, my point to OP went way over your head and you seem to have an ax to
grind with me. Take your churlish remarks and go fishing somewhere else.
--
Todd Vargo
:P
sKurt
2007-10-03 01:51:25 UTC
Permalink
billious wrote:
here is the code as run


::days.bat
:: de luxe version to accomodate XP 'date/t' breakages
:: NT/2K/XP required
:: version 3.02
:: set dd, mm, yy, yyyy, yyyymmdd to today - n
:: dow to day-of-week (1=Sun..7=Sat)
:: doy to day-of-year (1..365 or 366)
:: julian as yyddd (numeric - leading-zero suppressed)
:: julian_text as yyddd (with leading 0 padding to 5 characters)
:: ibm_julian as yyyyddd
:: since as days since 01/01/1901
:: dayname as name of day
:: day as 3-character abbreviation thereof
:: dd, mm, yy in leading-zero-filled format
:: first parameter is number of days, n - default is 1
:: second parameter is date - default is today

::@echo off
for %%u in (dd mm yy yyyy) do set %%u=
set daysoff=%1
if not defined daysoff set daysoff=1
set zt$=echo %2
if "%2"=="" set zt$=date/t
for /f "tokens=1,2,3,4 delims=/-. " %%w in ('%zt$%') do call :getdate
%%w %%x %%y %%z
::dd,mm - suppress leading zero
set /a dd=1%dd% - 100
set /a mm=1%mm% - 100
:negloop
if /i %daysoff%==0 goto final
if %daysoff% LSS 0 set /a yyyy=%yyyy%+4&set/a
daysoff=%daysoff%+1461&goto negloop
set /a daysoff=daysoff - 1

:SET30
set /A dd=%dd% - 1
if %dd% GTR 0 goto DONE
:: else last day of month - assume 31
set dd=31
set /A mm=%mm% - 1
if %mm% GTR 0 goto SETDAY
:: Must be Dec. 31st
set /A mm=12
set /A yyyy=%yyyy% - 1
goto DONE

:SETDAY
::Problem months are Feb, Apr,Jun,Sep and Nov
if %mm%==4 goto SET30
if %mm%==6 goto SET30
if %mm%==9 goto SET30
if %mm%==11 goto SET30
if not %mm%==2 goto DONE
:: February - default to 28 days (exception for leap years)
set /A dd=%yyyy% %% 4
if not %dd%==0 goto set28
set /A dd=%yyyy% %% 100
if not %dd%==0 goto set29
set /A dd=%yyyy% %% 400
if not %dd%==0 goto set28

:set29
set dd=29
goto done

:SET28
set dd=28

:DONE
if /i %daysoff%==0 goto final
if %dd% GTR %daysoff% goto thismonth
set /a daysoff=%daysoff% - %dd%
set dd=1
goto set30

:thismonth
set /a dd=%dd% - %daysoff%

:final
:: now convert back to 2-digit dd, mm and yy

if %mm% LSS 10 set mm=0%mm%
if %dd% LSS 10 set dd=0%dd%
set yy=%yyyy:~2,2%

:: calculate day-of-week, day-of-year
:: get (y mod 4) * 12 + m

set daysoff=0,31,59,90,120,151,181,212,243,273,304,334
set /a dow=1%mm% - 100
for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set /a doy=%%a +
1%dd% - 100
set /a dow=%yyyy% %% 4
set /a dow=%dow% * 12 + 1%mm% - 100
set
daysoff=0,31,60,91,121,152,182,213,244,274,305,335,366,397,425,456,486,5
17,547,578,609,639,670,700
if %dow% GTR 24 set
daysoff=731,762,790,821,851,882,912,943,974,1004,1035,1065,1096,1127,115
5,1186,1216,1247,1277,1308,1339,1369,1400,1430
if %dow% GTR 24 set /a dow=%dow% - 24
for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set zt$=%%a
set /a daysoff=%yyyy% / 4
set /a daysoff=%daysoff% * 1461
set /a dow=1%dd% - 96 + %daysoff% + %zt$%
set /a dow=%dow% %%7 + 1
for /f "tokens=%dow% delims=," %%a in
("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday") do set
dayname=%%a
set day=%dayname:~0,3%
set /a zt$=%yyyy% %% 4
if %zt$%==0 if 1%mm% GTR 102 set /a doy=%doy% + 1
set /a julian=1%yy% - 100
set /a julian=%julian% * 1000 + %doy%
set /a julian_text=100000 + %julian%
set julian_text=%julian_text:~1%
set ibm_julian=%yyyy%%julian_text:~2%

:: since 01/01/1901

set /a zt$=%yyyy% - 1901
set /a daysoff=%zt$% / 4
set /a since=365 * %zt$% + %daysoff% + %doy% - 1
for %%i in (zt$ daysoff) do set %%i=
set yyyymmdd=%yyyy%%mm%%dd%

::ECHO %YYYY%%MM%%DD%

GOTO :eof

:: from the four date components passed, determine the date

:getdate

set dd=%2&set mm=%3&set yy=%4

:: if XP, dayname may be missing

if not defined yy set dd=%1&set mm=%2&set yy=%3

:: if yy-mm-dd format, switch dd & yy

echo.|date|find "(y">nul
if not errorlevel 1 set yyyy=%dd%&set dd=%yy%&set yy=%yyyy%

:: if mm-dd-yy format, switch dd & mm

echo.|date|find "(m">nul
if not errorlevel 1 set yyyy=%dd%&set dd=%mm%&set mm=%yyyy%

:: Now process month names for XP

for %%Z in (01Jan 02Feb 03Mar 04Apr 05May 06Jun 07Jul 08Aug 09Sep 10Oct
11Nov 12Dec) do call :procmth %%Z

:: Ensure dd and mm have leading 0s if required

set yyyy=%dd:~1%
if not defined yyyy set dd=0%dd%
set yyyy=%mm:~1%
if not defined yyyy set mm=0%mm%
set yyyy=%yy:~1%
if not defined yyyy set yy=0%yy%

:: Ensure yy is 2-digit and yyyy 4-digit

set yyyy=%yy:~2%
if defined yyyy set yyyy=%yy%&goto setyy

:: yy is 2-digit

set yyyy=20%yy%
if %yyyy% GEQ 2080 set yyyy=19%yy%

:setyy

set yy=%yyyy:~2%
goto :eof

:procmth

set yyyymmdd=%mm:~0,3%
set yyyy=%1
set yyyy=%yyyy:~2%
if /i %yyyy% NEQ %yyyymmdd% goto :eof
set mm=%1
set mm=%mm:~0,2%
goto :eof

::days.bat ends

--
billious
2007-10-03 05:54:06 UTC
Permalink
Post by sKurt
here is the code as run
::days.bat
:: de luxe version to accomodate XP 'date/t' breakages
:: NT/2K/XP required
:: version 3.02
:: set dd, mm, yy, yyyy, yyyymmdd to today - n
:: dow to day-of-week (1=Sun..7=Sat)
:: doy to day-of-year (1..365 or 366)
:: julian as yyddd (numeric - leading-zero suppressed)
:: julian_text as yyddd (with leading 0 padding to 5 characters)
:: ibm_julian as yyyyddd
:: since as days since 01/01/1901
:: dayname as name of day
:: day as 3-character abbreviation thereof
:: dd, mm, yy in leading-zero-filled format
:: first parameter is number of days, n - default is 1
:: second parameter is date - default is today
for %%u in (dd mm yy yyyy) do set %%u=
set daysoff=%1
if not defined daysoff set daysoff=1
set zt$=echo %2
if "%2"=="" set zt$=date/t
for /f "tokens=1,2,3,4 delims=/-. " %%w in ('%zt$%') do call :getdate
%%w %%x %%y %%z
::dd,mm - suppress leading zero
set /a dd=1%dd% - 100
set /a mm=1%mm% - 100
:negloop
if /i %daysoff%==0 goto final
if %daysoff% LSS 0 set /a yyyy=%yyyy%+4&set/a
daysoff=%daysoff%+1461&goto negloop
set /a daysoff=daysoff - 1
:SET30
set /A dd=%dd% - 1
if %dd% GTR 0 goto DONE
:: else last day of month - assume 31
set dd=31
set /A mm=%mm% - 1
if %mm% GTR 0 goto SETDAY
:: Must be Dec. 31st
set /A mm=12
set /A yyyy=%yyyy% - 1
goto DONE
:SETDAY
::Problem months are Feb, Apr,Jun,Sep and Nov
if %mm%==4 goto SET30
if %mm%==6 goto SET30
if %mm%==9 goto SET30
if %mm%==11 goto SET30
if not %mm%==2 goto DONE
:: February - default to 28 days (exception for leap years)
set /A dd=%yyyy% %% 4
if not %dd%==0 goto set28
set /A dd=%yyyy% %% 100
if not %dd%==0 goto set29
set /A dd=%yyyy% %% 400
if not %dd%==0 goto set28
:set29
set dd=29
goto done
:SET28
set dd=28
:DONE
if /i %daysoff%==0 goto final
if %dd% GTR %daysoff% goto thismonth
set /a daysoff=%daysoff% - %dd%
set dd=1
goto set30
:thismonth
set /a dd=%dd% - %daysoff%
:final
:: now convert back to 2-digit dd, mm and yy
if %mm% LSS 10 set mm=0%mm%
if %dd% LSS 10 set dd=0%dd%
set yy=%yyyy:~2,2%
:: calculate day-of-week, day-of-year
:: get (y mod 4) * 12 + m
set daysoff=0,31,59,90,120,151,181,212,243,273,304,334
set /a dow=1%mm% - 100
for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set /a doy=%%a +
1%dd% - 100
set /a dow=%yyyy% %% 4
set /a dow=%dow% * 12 + 1%mm% - 100
set
daysoff=0,31,60,91,121,152,182,213,244,274,305,335,366,397,425,456,486,5
17,547,578,609,639,670,700
if %dow% GTR 24 set
daysoff=731,762,790,821,851,882,912,943,974,1004,1035,1065,1096,1127,115
5,1186,1216,1247,1277,1308,1339,1369,1400,1430
if %dow% GTR 24 set /a dow=%dow% - 24
for /f "tokens=%dow% delims=," %%a in ("%daysoff%") do set zt$=%%a
set /a daysoff=%yyyy% / 4
set /a daysoff=%daysoff% * 1461
set /a dow=1%dd% - 96 + %daysoff% + %zt$%
set /a dow=%dow% %%7 + 1
for /f "tokens=%dow% delims=," %%a in
("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday") do set
dayname=%%a
set day=%dayname:~0,3%
set /a zt$=%yyyy% %% 4
if %zt$%==0 if 1%mm% GTR 102 set /a doy=%doy% + 1
set /a julian=1%yy% - 100
set /a julian=%julian% * 1000 + %doy%
set /a julian_text=100000 + %julian%
set julian_text=%julian_text:~1%
set ibm_julian=%yyyy%%julian_text:~2%
:: since 01/01/1901
set /a zt$=%yyyy% - 1901
set /a daysoff=%zt$% / 4
set /a since=365 * %zt$% + %daysoff% + %doy% - 1
for %%i in (zt$ daysoff) do set %%i=
set yyyymmdd=%yyyy%%mm%%dd%
::ECHO %YYYY%%MM%%DD%
GOTO :eof
:: from the four date components passed, determine the date
:getdate
set dd=%2&set mm=%3&set yy=%4
:: if XP, dayname may be missing
if not defined yy set dd=%1&set mm=%2&set yy=%3
:: if yy-mm-dd format, switch dd & yy
echo.|date|find "(y">nul
if not errorlevel 1 set yyyy=%dd%&set dd=%yy%&set yy=%yyyy%
:: if mm-dd-yy format, switch dd & mm
echo.|date|find "(m">nul
if not errorlevel 1 set yyyy=%dd%&set dd=%mm%&set mm=%yyyy%
:: Now process month names for XP
for %%Z in (01Jan 02Feb 03Mar 04Apr 05May 06Jun 07Jul 08Aug 09Sep 10Oct
11Nov 12Dec) do call :procmth %%Z
:: Ensure dd and mm have leading 0s if required
set yyyy=%dd:~1%
if not defined yyyy set dd=0%dd%
set yyyy=%mm:~1%
if not defined yyyy set mm=0%mm%
set yyyy=%yy:~1%
if not defined yyyy set yy=0%yy%
:: Ensure yy is 2-digit and yyyy 4-digit
set yyyy=%yy:~2%
if defined yyyy set yyyy=%yy%&goto setyy
:: yy is 2-digit
set yyyy=20%yy%
if %yyyy% GEQ 2080 set yyyy=19%yy%
:setyy
set yy=%yyyy:~2%
goto :eof
:procmth
set yyyymmdd=%mm:~0,3%
set yyyy=%1
set yyyy=%yyyy:~2%
if /i %yyyy% NEQ %yyyymmdd% goto :eof
set mm=%1
set mm=%mm:~0,2%
goto :eof
::days.bat ends
Ah! Got it!

[24] excutes either "date/t" (if no parameter-2 is supplied) or "echo
parameter2_contents" (if parameter-2 IS supplied)

so, FOR TESTING, I added
[23a]set zt$=echo 09/29/07

to force an MM/DD/YY date

and FOR TESTING, I changed [124] to find "(d" rather than "(m" so the
element-swap would be invoked from MY 'DATE' command

This executed [125]if not errorlevel 1 set yyyy=%dd%&set dd=%mm%&set
mm=%yyyy%

with yyyy not set, dd set to 09 and mm set to 29.

This invoked the ubiquitous parse-time trap and evaluated to

[125]if not errorlevel 1 set yyyy=09&set dd=29&set mm=

so - mm was being nulled, which probably means that anyone using this
routine in a non-dd/mm/yy system has encountered an error and either fixed
it themselves or thrown their hands up in despair - or more likely, no-one
has used it :(

And the easy solution is

[120]:: if yy-mm-dd format, switch dd & yy
[121]echo.|date|find "(y">nul
[122]if not errorlevel 1 set dd=%yy%&set yy=%dd
123]:: if mm-dd-yy format, switch dd & mm
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set dd=%mm%&set mm=%dd%

where only [122] and [125] have changed - [120-122] are obviously only for
ymd date-styles, so may be irrelevant

This uses the parse-time characteristic in a good, if non-intuitive way,
evaluating [125] to

[125]if not errorlevel 1 set dd=29&set mm=09

as was intended.

Good catch.
billious
2007-10-03 06:00:36 UTC
Permalink
Post by billious
[120]:: if yy-mm-dd format, switch dd & yy
[121]echo.|date|find "(y">nul
[122]if not errorlevel 1 set dd=%yy%&set yy=%dd
123]:: if mm-dd-yy format, switch dd & mm
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set dd=%mm%&set mm=%dd%
where only [122] and [125] have changed - [120-122] are obviously only for
ymd date-styles, so may be irrelevant
This uses the parse-time characteristic in a good, if non-intuitive way,
evaluating [125] to
[125]if not errorlevel 1 set dd=29&set mm=09
as was intended.
Good catch.
Oops -
[122]if not errorlevel 1 set dd=%yy%&set yy=%dd%

(terminal "%" was missing)
sKurt
2007-10-03 17:24:00 UTC
Permalink
Post by billious
Post by billious
[120]:: if yy-mm-dd format, switch dd & yy
[121]echo.|date|find "(y">nul
[122]if not errorlevel 1 set dd=%yy%&set yy=%dd
123]:: if mm-dd-yy format, switch dd & mm
[124]echo.|date|find "(m">nul
[125]if not errorlevel 1 set dd=%mm%&set mm=%dd%
where only [122] and [125] have changed - [120-122] are obviously
only for ymd date-styles, so may be irrelevant
This uses the parse-time characteristic in a good, if non-intuitive
way, evaluating [125] to
[125]if not errorlevel 1 set dd=29&set mm=09
as was intended.
Good catch.
Oops -
[122]if not errorlevel 1 set dd=%yy%&set yy=%dd%
(terminal "%" was missing)
Caught that too :)

so it works for Today's day of year and Yesterday's day of year by using

DAYS.BAT 0 for Yesterday and Blank for Today

I'll examine the code more to find a random DOY setting.

i.e.

01/01/2007 = DOY 1
10/03/2007 = DOY 276
12/31/7007 = DOY 365

Thanks!

sKurt

--
Timo Salmi
2007-10-02 03:39:18 UTC
Permalink
Post by sKurt
Post by foxidrive
Simpler is a good thing in my book, Todd, so thanks for those
pointers. Here's an updated version, from V3 to V4
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
What's wrong with the solutions posted and the ones covered in
the inevitable

195399 May 17 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

254761 Nov 11 2005 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, 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:***@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
sKurt
2007-10-02 04:30:12 UTC
Permalink
Post by Timo Salmi
Post by sKurt
Post by foxidrive
Simpler is a good thing in my book, Todd, so thanks for those
pointers. Here's an updated version, from V3 to V4
Now if you could make this work with the Day of the Year number, I
would be in heaven ;)
What's wrong with the solutions posted and the ones covered in
the inevitable
195399 May 17 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
254761 Nov 11 2005 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
All the best, Timo
Prof. Salmi, I use your tsbats on a regular basis, thank you so much
for providing them. However, I didn't see one that covered DATE to Day
of Year?

perhaps I have missed something valuable

sKurt

--
Timo Salmi
2007-10-02 05:10:39 UTC
Permalink
Post by sKurt
Post by Timo Salmi
195399 May 17 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
254761 Nov 11 2005 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
Prof. Salmi, I use your tsbats on a regular basis, thank you so much
for providing them. However, I didn't see one that covered DATE to Day
of Year?
Covered in at least EDATE.COM within the first of the packages. And
148} How to calculate the day-of-year number with a pure cmd script?

In the latter at least
143) How do I get the week number? What about the day of the year?

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:***@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
sKurt
2007-10-02 05:49:10 UTC
Permalink
Post by Timo Salmi
In the latter at least
143) How do I get the week number? What about the day of the year?
All the best, Timo
Holy cow... How did I totally miss that! Once again the 'list' to the
rescue. Plus I learned a bunch from the other suggestions, now to work
them all together and see how to use them best.

Thanks again!

sKurt

--
sKurt
2007-10-02 06:04:16 UTC
Permalink
Post by Timo Salmi
In the latter at least
143) How do I get the week number? What about the day of the year?
All the best, Timo
Yes! that works for today's date, however, how do I get a specified
date?

like 09/01/2007 or 05/04/2007 etc.?


Thanks!

sKurt
--
Timo Salmi
2007-10-02 08:30:14 UTC
Permalink
Post by sKurt
Post by Timo Salmi
In the latter at least
143) How do I get the week number? What about the day of the year?
Yes! that works for today's date, however, how do I get a specified
date?
Off the top of my head. That concerns the MS-DOS+Win../95/98/Me case.
Replace systime() in the gawk function with the the specified date. I
don't recall the format outright. And being in the middle of another
task I cant look it up right now.

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:***@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
Continue reading on narkive:
Loading...