计算第几周的也做成函数- ::计算指定日期是当年第几周,函数:weekord
- @echo off
- setLocal enableDelayedExpansion
-
- set idate=%date%
- call :picknum idate today
- call :weekord today wo
- echo/ 今天是今年第%wo%周
-
- set idate=2021-01-23
- set fdate=%idate:-=%
- call :weekord fdate wo
- echo/ %idate%是当年第%wo%周
-
- pause
- goto :eof
-
- ::提取字串中的数字
- :picknum str numstr
- setlocal
- set "str=!%1!"
- for /l %%n in (0,1,9)do set _%%n=1
- :_picknext
- if defined _%str:~,1% set num=%num%%str:~,1%
- set str=%str:~1%
- if not "%str%"=="" goto :_picknext
- endlocal&set %2=%num%
- goto :eof
-
- ::计算日期是当年第几周。参数YYYYMMDD,输出1-54
- :weekord formatdate weekordinal
- setlocal
- set "fdate=!%1!"
- set/a y=1%fdate:~,4%-10000,m=1%fdate:~4,2%-100,d=1%fdate:~6,2%-100
- set/a y1=y-1,m3=(m-1)*3
- set/a "leap=^!(y%%4)&^!^!(y%%100)|^!(y%%400)",T2=28+leap
- set daysofmonth=+31+T2+31+30+31+30+31+31+30+31+30+31
- set/a daysnum=0!daysofmonth:~,%m3%!+d,daysmore=y1/4-y1/100+y1/400+y1
- set/a wday0=daysmore%%7,wday=(daysmore+daysnum)%%7
- set/a weeko=(wday0+daysnum+(7-wday)%%7)/7
- endlocal&set %2=%weeko%
- goto :eof
复制代码
|