计算日期-10天

时间:2013-07-02 22:15:44

标签: windows date batch-file cmd

我是批处理脚本的新手。目前我的文件以下面的格式显示。我希望详细输出日期应该是currentdate之前的10天(表示日期-10)。目前它在最新日期显示

00000064  xxyz                 2013-06-17 14:37:11      
00000065  xxyz                 2013-06-17 14:46:15      
00000066  xxyz                 2013-06-17 14:52:34      
0000006d  xxyz                 2013-06-18 11:17:42      
0000006e  xxyz                 2013-06-18 11:29:57      
0000006f  xxyz                 2013-06-18 11:50:53      
00000070  xxyz                 2013-06-18 12:17:56      
00000074  xxyz                 2013-06-19 11:45:36      
00000001  xxyz                 2013-06-19 15:22:07      
00000002  xxyz                 2013-06-19 16:12:45      
00000003  xxyz                 2013-06-19 16:19:42      
00000006  xxyz                 2013-06-19 20:36:46      
00000008  xxyz                 2013-06-19 23:34:11      
0000000f  xxyz                 2013-06-20 10:49:38      
00000010  xxyz                 2013-06-20 10:50:59      
00000011  xxyz                 2013-06-20 10:52:29      
00000018  xxyz                 2013-06-20 15:58:24      
0000006e  xxyz                 2013-06-25 07:11:00      
0000007f  xxyz                 2013-06-26 08:55:36      
00000080  xxyz                 2013-06-26 09:08:14      
00000081  xxyz                 2013-06-26 09:28:57      
00000082  xxyz                 2013-06-26 13:49:31      
00000083  xxyz                 2013-06-26 14:00:53      
00000087  xxyz                 2013-06-27 10:00:27      
0000008b  xxyz                 2013-06-27 12:40:53      
00000091  xxyz                 2013-06-27 15:32:15      

2 个答案:

答案 0 :(得分:3)

您可以使用GNU for Windows执行此操作:

awk -F"[-: ]+" "{print $1,$2,\"\t\t\t\",strftime(\"%F %T\",mktime($3\" \"$4\" \"$5\" \"$6\" \"$7\" \"$8)-864000)}" file
>awk -F"[-: ]+" "{print $1,$2,\"\t\t\t\",strftime(\"%F %T\",mktime($3\" \"$4\" \"$5\" \"$6\" \"$7\" \"$8)-864000)}" file
00000064 xxyz                    2013-06-07 14:37:11
00000065 xxyz                    2013-06-07 14:46:15
00000066 xxyz                    2013-06-07 14:52:34
0000006d xxyz                    2013-06-08 11:17:42
0000006e xxyz                    2013-06-08 11:29:57
0000006f xxyz                    2013-06-08 11:50:53
00000070 xxyz                    2013-06-08 12:17:56
00000074 xxyz                    2013-06-09 11:45:36
00000001 xxyz                    2013-06-09 15:22:07
00000002 xxyz                    2013-06-09 16:12:45
00000003 xxyz                    2013-06-09 16:19:42
00000006 xxyz                    2013-06-09 20:36:46
00000008 xxyz                    2013-06-09 23:34:11
0000000f xxyz                    2013-06-10 10:49:38
00000010 xxyz                    2013-06-10 10:50:59
00000011 xxyz                    2013-06-10 10:52:29
00000018 xxyz                    2013-06-10 15:58:24
0000006e xxyz                    2013-06-15 07:11:00
0000007f xxyz                    2013-06-16 08:55:36
00000080 xxyz                    2013-06-16 09:08:14
00000081 xxyz                    2013-06-16 09:28:57
00000082 xxyz                    2013-06-16 13:49:31
00000083 xxyz                    2013-06-16 14:00:53
00000087 xxyz                    2013-06-17 10:00:27
0000008b xxyz                    2013-06-17 12:40:53
00000091 xxyz                    2013-06-17 15:32:15
每10天

秒= 864000

答案 1 :(得分:1)

以下是批处理文件中可以计算日期的通用VBS脚本。

:: Date foward & backward
@echo off
if "%~2"=="" (
echo to get todays date use         call "%~n0" today 0
echo to get yesterdays date use     call "%~n0" today -1
echo to get 25 days before 19441213 call "%~n0" 1944/12/13 -25
echo to get 1250 days in the future call "%~n0" today 1250
echo.
echo Add a third parameter if you want a separator in the date string
echo EG: to use - as in YYYY-MM-DD for today's date
echo     call "%~n0" today 0 -
echo.
pause
goto :EOF)

set date1=%1
set qty=%2
set separator=%~3
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%%separator%%result:~4,2%%separator%%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)
pause