Any ideas(simpler) to calculate day of the year?
What I can come up so far is to:
1. use 'map and lookup' idea by creating a string which maps the month to total number of days in previous month like:
set days=01-00;02-31;03-59;04-90 ...
2. add the resulting value from month to the day value
3. adjust the result by checking whether it is leap year or not
-Frank
Batch script to show day of the year?
Moderator: DosItHelp
chcfrank,
Here is a new function.
http://www.dostips.com/DtCodeCmdLib.php ... _dayOfYear
Output:
DOS IT HELP?
Here is a new function.
http://www.dostips.com/DtCodeCmdLib.php ... _dayOfYear
Code: Select all
@ECHO OFF
call:dayOfYear day 1/1/2008
echo.%day%
call:dayOfYear day "%date%"
echo.%day%
call:dayOfYear day 12/31/2008
echo.%day%
GOTO:EOF
rem insert :dayOfYear function here ....
Output:
Code: Select all
1
168
366
DOS IT HELP?

Re: Batch script to show day of the year?
VBS:
Saso
Code: Select all
@echo off
set yyyy=2025
set mm=12
set dd=31
>tmp.vbs echo wscript.stdout.write 1+DateDiff("y", "%yyyy%-01-01", "%yyyy%-%mm%-%dd%")
for /f %%A In ('cscript tmp.vbs //noLogo') do set doy=%%A
if exist tmp.vbs del tmp.vbs
echo %doy%