有人用VBS搞,有人用复杂的for函数等等,可是其实很简单:
echo %date:~0,4%%date:~5,2%%date:~8,2%显示为:20101101 echo %date:~0,10% 显示为:2010-11-01
换句话说,环境变量格式想怎么来就怎么来。
以下自己的一个测试时的命令行批处理脚本,功能是组织出日期参数传递给一个Python程序:
@echo off echo 生成成功及冲正凭证数据... python gsfpsc.pyc -s 20100829 -e 20100831 -d c:\kk -p 10 -m 6000 -S"select top 100 ltrim(rtrim(b.drawid)),right(a.rcdat1,8),str_replace(convert(char(10),a.trandt,102),'.','-'), convert(varchar,a.tranam),ltrim(rtrim(a.rcdat3)),case a.transt when '1' then '10' when '2' then '20' when '4' then '20' end from zzztest a, mdf_btod b where a.mbcode='00000006' and a.trandt >=@bgindt and a.trandt <=@enddt and a.transt in('1','2','4') and b.dcmttp='AGNT' and left(a.rcdat1,4)=b.btchno order by a.rcdat1" if errorlevel 1 goto :end echo -------------------------------------------------------------- echo 生成各种作废凭证数据... python gsfpsc.pyc -s 20101101 -e 20101101 -d c:\kk -p 10 -m 6000 -I -S"select top 100 ltrim(rtrim(b.drawid)),right(a.initno,8),str_replace(convert(char(10),a.drawdt,102),'.','-'), '','',a.drawtg from mdf_draw a,mdf_btod b where a.dcmttp ='AGNT' and a.drawdt>=@bgindt and a.drawdt <=@enddt and left(a.initno,4)=b.btchno order by a.initno" if errorlevel 1 goto :end echo -------------------------------------------------------------- set tmpdate=%date:~0,4%%date:~5,2%%date:~8,2% echo 创建压缩文件至c:\kk\410123456789999_%tmpdate%.zip... if exist c:\kk\410123456789999_%tmpdate%.zip (del c:\kk\410123456789999_%tmpdate%.zip) 7za.exe a c:\kk\410123456789999_%tmpdate%.zip -tzip c:\kk\WLFP-%date:~0,10%\*.xml >zip.log if errorlevel 1 goto :end echo -------------------------------------------------------------- echo 压缩文件创建成功 echo -------------------------------------------------------------- dir c:\kk\410123456789999_%tmpdate%.zip :end @echo on
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/260.html