网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 批处理bat计算前n个月第一天的日期
范文
    【方案一】bat + date.exe(gnu)
    代码如下:
    @echo off
    rem 调用gnu for win32的date.exe
    set gnudate=c:/test/date.exe
    rem 指定月数
    set monthsago=1
    for /f %%a in ('%gnudate% -d %monthsago% months ago +%%y-%%m-01') do (
        set dstdate=%%a
        )
    )
    echo,%dstdate%
    pause
    【方案二】bat + vbs
    代码如下:
    @echo off
    rem 指定月数
    set monthsago=2
    >%temp%/datecalculate.vbs echo strlastdate=dateadd(m, -%monthsago%, date)
    >>%temp%/datecalculate.vbs echo strfmtdate=right(year(strlastdate),4) ^& right(0 ^& month(strlastdate),2) ^& 01
    >>%temp%/datecalculate.vbs echo wscript.echo strfmtdate
    for /f %%a in ('cscript /nologo %temp%/datecalculate.vbs') do (
        set dstdate=%%a
    )
    set dstdate=%dstdate:~0,4%-%dstdate:~4,2%-%dstdate:~6,2%
    echo,%dstdate%
    pause
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/6/18 4:47:35