windows - How to get the day of year in a batch file -


how can day of year current date in windows batch file?

i have tried

set /a dayofyear=(%date:~0,2%*30.5)+%date:~3,2% 

but not work leap years, , off few days. not use third-party executables.

if want julian day number, may use method posted in my accepted answer given @ previous link. however, "day of year" number between 1 , 365 (366 leap years). batch file below correctly calculate it:

@echo off setlocal enabledelayedexpansion  set /a i=0, sum=0 %%a in (31 28 31 30 31 30 31 31 30 31 30 31) (    set /a i+=1    set /a accum[!i!]=sum, sum+=%%a )  set /a month=1%date:~0,2%-100, day=1%date:~3,2%-100, yearmod4=%date:~6,4% %% 4 set /a dayofyear=!accum[%month%]!+day if %yearmod4% equ 0 if %month% gtr 2 set /a dayofyear+=1  echo %dayofyear% 

note: relies on date format mm/dd/yyyy.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -